7 display a simple form from a ejs Form object
10 f.action = action to be taken on submit (optional, defaults to current page)
11 f.class = css class (optional, defaults to 'form')
12 f.submit = an array of submit labels
13 f.add(name, label, [type], [value]) =
15 f.element[i].label = element label
16 f.element[i].name = element name (defaults to label)
17 f.element[i].type = element type (defaults to text)
18 f.element[i].value = current value (optional, defaults to "")
20 function form_display() {
23 write('<form name="' + f.name +
24 '" method="post" action="' + f.action +
25 '" class="' + f.class + '">\n');
26 if (f.element.length > 0) {
29 for (i in f.element) {
31 if (e.name == undefined) {
34 if (e.value == undefined) {
37 if (strlen(e.value) > size) {
38 size = strlen(e.value) + 4;
41 for (i in f.element) {
44 write("<td>" + e.label + "</td>");
45 if (e.type == "select") {
46 write('<td><select name="' + e.name + '">\n');
48 if (e.value == e.list[s]) {
49 write('<option selected=selected>' + e.list[s] + '</option>\n');
51 write('<option>' + e.list[s] + '</option>\n');
54 write('</select></td>\n');
57 if (e.type == "text" || e.type == "password") {
58 sizestr = sprintf('size="%d"', size);
60 writef('<td><input name="%s" type="%s" value="%s" %s /></td>\n',
61 e.name, e.type, e.value, sizestr);
65 if (f.element.length > 0) {
69 write('<input name="submit" type="submit" value="' + f.submit[i] + '" />\n');
74 function __addMethod(name, label)
77 var i = f.element.length;
78 f.element[i] = new Object();
79 f.element[i].name = name;
80 f.element[i].label = label;
81 f.element[i].type = "text";
82 f.element[i].value = "";
83 if (arguments.length > 2) {
84 f.element[i].type = arguments[2];
86 if (arguments.length > 3) {
87 f.element[i].value = arguments[3];
92 create a Form object with the defaults filled in, ready for display()
94 function FormObj(name, num_elements, num_submits)
98 f.element = new Array(num_elements);
99 f.submit = new Array(num_submits);
100 f.action = session_uri(request.REQUEST_URI);
101 f.class = "defaultform";
103 for (i in f.element) {
104 f.element[i] = new Object();
105 f.element[i].type = "text";
106 f.element[i].value = "";
108 f.display = form_display;