diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-04-04 18:08:35 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-04-04 18:08:35 +0100 |
commit | d9f66a567a831ce4ad655b6af1797ef4b166ba51 (patch) | |
tree | f885db4f321d5dec89fe99cbabc2855ae5cbd5d4 /util | |
parent | dd4c9e6eece3c29c902d818eda9c0a87534b3147 (diff) | |
download | prosody-d9f66a567a831ce4ad655b6af1797ef4b166ba51.tar.gz prosody-d9f66a567a831ce4ad655b6af1797ef4b166ba51.zip |
util.dataforms: Support for retriving the field value data from forms
Diffstat (limited to 'util')
-rw-r--r-- | util/dataforms.lua | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua index 3c979bcc..a57e183b 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -72,10 +72,65 @@ function form_t.form(layout, data) return form; end +local field_readers = {}; + function form_t.data(layout, stanza) + local data = {}; + for field_tag in stanza:childtags() do + local field_type = field_tag.attr.type; + + local reader = field_readers[field_type]; + if reader then + data[field_tag.attr.var] = reader(field_tag); + end + + end + return data; end +field_readers["text-single"] = + function (field_tag) + local value = field_tag:child_with_name("value"); + if value then + return value[1]; + end + end + +field_readers["text-private"] = + field_readers["text-single"]; + +field_readers["text-multi"] = + function (field_tag) + local result = {}; + for value_tag in field_tag:childtags() do + if value_tag.name == "value" then + result[#result+1] = value_tag[1]; + end + end + return t_concat(result, "\n"); + end + +field_readers["boolean"] = + function (field_tag) + local value = field_tag:child_with_name("value"); + if value then + if value[1] == "1" or value[1] == "true" then + return true; + else + return false; + end + end + end + +field_readers["hidden"] = + function (field_tag) + local value = field_tag:child_with_name("value"); + if value then + return value[1]; + end + end + return _M; |