summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--swat/esptest/exception.esp6
-rw-r--r--swat/esptest/formtest.esp36
-rw-r--r--swat/esptest/session.esp13
-rw-r--r--swat/esptest/showvars.esp8
-rw-r--r--swat/login.esp14
-rw-r--r--swat/scripting/common.js57
6 files changed, 81 insertions, 53 deletions
diff --git a/swat/esptest/exception.esp b/swat/esptest/exception.esp
index abea890d98..cfd0f312fa 100644
--- a/swat/esptest/exception.esp
+++ b/swat/esptest/exception.esp
@@ -5,16 +5,10 @@
<form name="ExceptionTest" method="POST" action="@@request['SCRIPT_NAME']">
<input name="submit" type="submit" value="Generate Exception">
<input name="submit" type="submit" value="No Exception">
- <input name="submit" type="submit" value="Cancel"><br>
</form>
<%
if (request['REQUEST_METHOD'] == "POST") {
- /* if they cancelled then take them back to the list of tests */
- if (form['submit'] == "Cancel") {
- redirect("/");
- }
-
function TestFunction(arg1, arg2) {
return "OK";
}
diff --git a/swat/esptest/formtest.esp b/swat/esptest/formtest.esp
index 89e542c552..2d3693355c 100644
--- a/swat/esptest/formtest.esp
+++ b/swat/esptest/formtest.esp
@@ -1,34 +1,26 @@
<% page_header("columns", "ESP Form Test"); %>
-<form name="FormTest" method="POST" action="@@request['SCRIPT_NAME']">
- firstName: <input name="firstName" type="text" value=""><br>
- lastName: <input name="lastName" type="text" value=""><br>
- <input name="submit" type="submit" value="OK">
- <input name="submit" type="submit" value="Cancel"><br>
-</form>
+<%
+var f = Form("FormTest", 2, 2);
+f.element[0].label = "First Name";
+f.element[0].name = "firstName";
+f.element[1].label = "Last Name";
+f.element[1].name = "lastName";
+f.submit[0] = "OK";
+f.submit[1] = "Cancel";
+
+display_form(f);
<%
/* if its a post then the user has filled in the form, so
report the values
*/
- if (request['REQUEST_METHOD'] == "POST") {
-
- /* if they cancelled then take them back to the list of tests */
- if (form['submit'] == "Cancel") {
- redirect("/");
- }
+ if (form['OK']) {
%>
- You chose firstName=@@form['firstName'] lastName=@@form['lastName']
+ You chose firstName=@@form['firstName'] lastName=@@form['lastName']<p>
+
<%
-
- function showArray(name, array) {
- write("<h3>Array: " + name + "</h3>\n");
- for (v in array) {
- write(name + "[" + v + "]=" + array[v] + "<br>\n");
- }
- }
-
- showArray("form", form);
+ simple_table(form);
}
%>
diff --git a/swat/esptest/session.esp b/swat/esptest/session.esp
index 3d787012c6..ec747df442 100644
--- a/swat/esptest/session.esp
+++ b/swat/esptest/session.esp
@@ -43,18 +43,7 @@ if (request['REQUEST_METHOD'] == "POST") {
}
}
-function showArray(name, array) {
- write("<h3>Array: " + name + "</h3>\n");
- if (array == undefined) {
- write("undefined<br>\n");
- return;
- }
- for (v in array) {
- write(name + "[" + v + "]=" + array[v] + "<br>\n");
- }
-}
-
-showArray("session", session);
+simple_table(session);
write("SessionId=" + request['SESSION_ID'] + "<br>\n");
%>
diff --git a/swat/esptest/showvars.esp b/swat/esptest/showvars.esp
index 262a0962b7..40008a0d7d 100644
--- a/swat/esptest/showvars.esp
+++ b/swat/esptest/showvars.esp
@@ -8,9 +8,7 @@
if (array == undefined) {
write("undefined<br>\n");
} else {
- for (v in array) {
- write(name + "[" + v + "]=" + array[v] + "<br>\n");
- }
+ simple_table(array);
}
}
@@ -23,10 +21,6 @@
showArray("session", session);
%>
-<form name="Cancel" method="POST" action="/">
- <input name="submit" type="submit" value="Cancel"><br>
-</form>
-
</ul>
<% page_footer(); %>
diff --git a/swat/login.esp b/swat/login.esp
index 1dfc1142e6..5d12af2258 100644
--- a/swat/login.esp
+++ b/swat/login.esp
@@ -1,11 +1,13 @@
<% page_header("plain", "SWAT Login"); %>
-<form name="login" method="POST" action="@@request.SCRIPT_NAME">
- Username: <input name="Username" type="text" value=""><br>
- Password: <input name="Password" type="password" value=""><br>
- <br>
- <input name="submit" type="submit" value="Login"><br>
-</form>
+<%
+var f = Form("login", 2, 1);
+f.element[0].label = "Username";
+f.element[1].label = "Password";
+f.submit[0] = "Login";
+
+display_form(f);
+%>
<%
if (request.REQUEST_METHOD == "POST") {
diff --git a/swat/scripting/common.js b/swat/scripting/common.js
index cc3ca55468..d9e3b56bce 100644
--- a/swat/scripting/common.js
+++ b/swat/scripting/common.js
@@ -92,3 +92,60 @@ function multi_table(array, header) {
}
write("</table>\n");
}
+
+/*
+ create a Form object with the defaults filled in, ready for display_form()
+ */
+function Form(name, num_elements, num_submits)
+{
+ var f = new Object();
+ f.name = name;
+ f.element = new Array(num_elements);
+ f.submit = new Array(num_submits);
+ f.action = request.REQUEST_URI;
+ f.class = "form";
+ for (i in f.element) {
+ f.element[i] = new Object();
+ f.element[i].type = "text";
+ f.element[i].value = "";
+ }
+ return f;
+}
+
+/*
+ display a simple form from a ejs Form object
+ caller should fill in
+ f.name = form name
+ f.action = action to be taken on submit (optional, defaults to current page)
+ f.class = css class (optional, defaults to 'form')
+ f.submit = an array of submit labels
+ f.element[i].label = element label
+ f.element[i].name = element name (defaults to label)
+ f.element[i].type = element type
+ f.element[i].value = current value (optional, defaults to "")
+ */
+function display_form(f) {
+ write('<form name="' + f.name +
+ '" method="post" action="' + f.action +
+ '" class="' + f.class + '">\n');
+ write("<table>\n");
+ for (i in f.element) {
+ var e = f.element[i];
+ if (e.name == undefined) {
+ e.name = e.label;
+ }
+ if (e.value == undefined) {
+ e.value = '""';
+ }
+ write("<tr>");
+ write("<td>" + e.label + "</td>");
+ write('<td><input name="' + e.name + '" type="' +
+ e.type + '" value="' + e.value + '"></td>\n');
+ }
+ write("</table>\n");
+ for (i in f.submit) {
+ write('<input name="' + f.submit[i] +
+ '" type="submit" value="' + f.submit[i] + '">\n');
+ }
+ write("</form>\n");
+}