4 local xmlns_forms = 'jabber:x:data';
7 local form_mt = { __index = form_t };
10 return setmetatable(layout, form_mt);
13 local form_x_attr = { xmlns = xmlns_forms };
15 function form_t.form(layout, data)
16 local form = st.tag("x", form_x_attr);
17 for n, field in ipairs(layout) do
18 local field_type = field.type;
20 form:tag("field", { type = field_type, var = field.name });
22 local value = data[field.name];
24 -- Add value, depending on type
25 if field_type == "hidden" then
26 if type(value) == "table" then
27 -- Assume an XML snippet
28 form:add_child(value);
30 form:text(tostring(value));
32 elseif field_type == "boolean" then
33 form:text((value and "1") or "0");
34 elseif field_type == "fixed" then
36 elseif field_type == "jid-multi" then
37 for _, jid in ipairs(value) do
38 form:tag("value"):text(jid):up();
40 elseif field_type == "jid-single" then
41 form:tag("value"):text(value):up();
45 -- Jump back up to list of fields
51 function form_t.data(layout, stanza)
62 title = "MUC Configuration",
63 instructions = [[Use this form to configure options for this MUC room.]],
65 { name = "FORM_TYPE", type = "hidden", required = true };
66 { name = "field-name", type = "field-type", required = false };