summaryrefslogtreecommitdiff
path: root/web/src/cgi.tcl-1.10/example/validate.cgi
diff options
context:
space:
mode:
authorEduardo Chappa <echappa@gmx.com>2013-02-03 00:59:38 -0700
committerEduardo Chappa <echappa@gmx.com>2013-02-03 00:59:38 -0700
commit094ca96844842928810f14844413109fc6cdd890 (patch)
treee60efbb980f38ba9308ccb4fb2b77b87bbc115f3 /web/src/cgi.tcl-1.10/example/validate.cgi
downloadalpine-094ca96844842928810f14844413109fc6cdd890.tar.xz
Initial Alpine Version
Diffstat (limited to 'web/src/cgi.tcl-1.10/example/validate.cgi')
-rwxr-xr-xweb/src/cgi.tcl-1.10/example/validate.cgi76
1 files changed, 76 insertions, 0 deletions
diff --git a/web/src/cgi.tcl-1.10/example/validate.cgi b/web/src/cgi.tcl-1.10/example/validate.cgi
new file mode 100755
index 00000000..c104b7b5
--- /dev/null
+++ b/web/src/cgi.tcl-1.10/example/validate.cgi
@@ -0,0 +1,76 @@
+#!/depot/path/tclsh
+
+# This CGI script uses JavaScript to validate a form before submission.
+
+package require cgi
+
+cgi_eval {
+ source example.tcl
+
+ cgi_input
+
+ cgi_head {
+ title "Using JavaScript to validate a form before submission"
+
+ javascript {
+ puts {
+ function odd(num) {
+ if (num.value % 2 == 0) {
+ alert("Please enter an odd number!")
+ num.value = ""
+ return false
+ }
+ return true
+ }
+ }
+ }
+ noscript {
+ puts "Sorry - your browser doesn't understand JavaScript."
+ }
+ }
+
+ set rownum 0
+ proc row {msg {event {}}} {
+ global rownum
+
+ incr rownum
+ table_row {
+ table_data nowrap {
+ put "Odd number: "
+ text num$rownum= size=4 $event
+ }
+ table_data {
+ puts $msg
+ }
+ }
+ }
+
+ cgi_body {
+ set more ""
+ if {0 == [catch {import num3}]} {
+ set count [scan $num3 %d num]
+ if {($count != 1) || ($num % 2 == 0)} {
+ p "Hey, you didn't enter an odd number!"
+ } else {
+ p "Thanks for entering odd numbers!"
+ set more " more"
+ }
+ }
+
+ puts "Please enter$more odd numbers - thanks!"
+
+ cgi_form validate "onSubmit=return odd(this.num2)" {
+ table {
+ row "This number will be validated when it is entered." onChange=odd(this.form.num1)
+ row "This number will be validated when the form is submitted."
+ row "This number will be validated after the form is submitted."
+ }
+ submit_button =Submit
+ }
+
+ h5 "Note: JavaScript validation should always be accompanied
+ by validation in the backend (CGI script) since browsers
+ cannot be relied upon to have JavaScript enabled (or supported
+ in the first place). Sigh."
+ }
+}