Merge Zash->trunk
[prosody.git] / util / dataforms.lua
index 5626172e15fc614e62ab99d568b32c4e684b8a9b..5a3b1fb5652c969fb1cc5e329dcae8dbca04613d 100644 (file)
@@ -1,6 +1,6 @@
 -- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
 -- 
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
@@ -23,8 +23,8 @@ function new(layout)
        return setmetatable(layout, form_mt);
 end
 
-function form_t.form(layout, data)
-       local form = st.stanza("x", { xmlns = xmlns_forms, type = "form" });
+function form_t.form(layout, data, formtype)
+       local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype or "form" });
        if layout.title then
                form:tag("title"):text(layout.title):up();
        end
@@ -93,7 +93,13 @@ function form_t.data(layout, stanza)
        local data = {};
        
        for field_tag in stanza:childtags() do
-               local field_type = field_tag.attr.type;
+               local field_type;
+               for n, field in ipairs(layout) do
+                       if field.name == field_tag.attr.var then
+                               field_type = field.type;
+                               break;
+                       end
+               end
                
                local reader = field_readers[field_type];
                if reader then