#! ../bin/wisp -ce Content-type: text/html; charset=utf-8 Pragma: no-cache Expires: Fri, 1 Sep 2000 00:00:00 +0000 |: (use cgi strings time) :| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Name list demo</title> <link rel="stylesheet" href="../wisp.css" type="text/css"> </head> <body class=white> <h1 style="text-align: center">Name list demo</h1> <div style="text-align: center"> <table cellpadding=16> <tr><td style="color: black; background-color: #ffffc0"> |: (define time (unix-time)) :| It's currently [: time :] o' Unix clock. <p> |: (define time-parts (posix-time->utc time)) :| Therefore, have a nice [: (vector-ref '#("January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December") (- (second time-parts) 1)) :] [: (my mday (third time-parts) (string-append (integer->string mday) (cond ((and (>= mday 4) (<= mday 19)) "th") ((= (remainder mday 10) 1) "st") ((= (remainder mday 10) 2) "nd") ((= (remainder mday 10) 3) "rd") (else "th")))) :] [: (first time-parts) :] CE! <p> <form action="names.cgi" method=get> |: (define *whole-list* (make-box '())) ;; I urge you to acknowledge that it's very insecure to have the user maintain ;; his status data and send it back to you and thusly, it should NOT be done. ;; HOWEVER, by doing this in a demo like this, maybe you, a potential ;; developer, can see for yourself why this is so bad. ;; Besides, it makes the Lisp-style CGI processing much more apparent. (let ((old (dict-fetch *cgi-query* 'old)) (inp (dict-fetch *cgi-query* 'inp))) (if inp (begin (car! inp) (set! inp (string-join (string->word-list inp))) (if (string=? inp "") (print "Toggle an empty name, huh?<p>\n") (if old (begin (car! old) (if (not (cons? old)) (set! old (list old))) (my filt? #f (set! old (collect (lambda (emit) (for-each (lambda (vi) (cond ((string=? vi inp) (set! filt? #t)) ((string-ci=? vi inp) (set! filt? #t) (emit inp)) (else (emit vi)))) old) (if (not filt?) (emit inp))))))) (set! old (list inp)))) (set! (box-ref *whole-list*) old) (print "<p>Your list has $(length (box-ref *whole-list*)) names so far") (if (not (null? (box-ref *whole-list*))) (print ", as follows")) (print ".</p>\n") (if (not (box-ref *whole-list*)) (set! (box-ref *whole-list*) '())) (if (not (null? (box-ref *whole-list*))) (begin (print "<ol>\n") (for-each (lambda (n) (print "<li> $,[n]\n") (print "<input type=hidden name=old value=\"$,[n]\">\n")) (box-ref *whole-list*)) (print "</ol>\n")))))) :| <p>Name: <input name=inp> <input type=submit value=Toggle></p> </form> </td></tr> <tr><td style="width: 24em"> Whenever you enter a name and hit the Toggle button, the name will be added to the list above|: (if (null? (box-ref *whole-list*)) (print " (which is not shown currently \ because it's empty)")) :|. If the name happens to be there already, it's, contrariwise, removed. <p> Note that this application is case knowledgeable.<p> That's it. <p> Well, the <a href="show.cgi?file=names.cgi">source</a> is available too. <p> And finally, you might want to validate that this machine-generated page uses <a href="http://validator.w3.org/check/referer">valid HTML</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer">valid CSS</a>. </td></tr> </table> </div> </body> </html> |: #| vim: set ft=ewisp: |# :|
This listing was generated by a
See the listing of the lister.
Validate this listing.