sunet/web-server/root/surflets/add-html.scm

61 lines
1.7 KiB
Scheme
Raw Normal View History

2003-01-19 11:57:27 -05:00
(define-structure surflet surflet-interface
(open surflets
surflets/utilities ;form-query-list
surflet-requests
surflet-handler/primitives
2002-10-09 11:22:50 -04:00
httpd-responses
url
scheme-with-scsh)
(begin
(define (get-number input-text . maybe-title)
(let* ((title (if (pair? maybe-title) (car maybe-title) #f))
2003-01-17 12:48:20 -05:00
(result
(send-html/suspend
(lambda (new-url)
`(html ,(if title
`(title ,title) '())
(body
,(if title `(h2 ,title) '())
(p
(form (@ (method "get")
(action ,new-url))
,input-text " "
(input (@ (type "text")
(name "number"))
(input (@ (type "submit"))))))
(hr)
(p (url "/" "Return to main menu") (br)
(url "add-html.scm" "Start new calculation."))))))))
(let* ((bindings (form-query-list
(http-url-search (surflet-request-url result))))
(number (string->number
(extract-single-binding "number" bindings))))
(if number
number
2002-10-09 11:22:50 -04:00
(get-number input-text "Please enter a valid number")))))
(define (get-number1)
2002-10-09 11:22:50 -04:00
(get-number "First number:" "Calculation - Step one"))
(define (get-number2)
2002-10-09 11:22:50 -04:00
(get-number "Second number:" "Calculation - Step two"))
(define (main req)
2002-10-09 11:22:50 -04:00
(let ((req
(send-html/suspend
(lambda (new-url)
`(html (title "Result")
2003-01-16 07:09:49 -05:00
(body (h2 "Result")
2002-10-09 11:22:50 -04:00
(p ,(number->string (+ (get-number1) (get-number2))))
2003-01-16 07:09:49 -05:00
(hr)
2003-02-21 04:49:35 -05:00
(a (@ (href "add-html.scm")) "New calculation (new session)")(br)
2003-01-19 12:26:56 -05:00
(a (@ (href "javascript:history.go(-2)")) "New calculation (same session)")(br)
2003-01-16 07:09:49 -05:00
(a (@ (href ,new-url)) "Close this session")))))))
;; How to clear session data and go to another HTML page:
(send-error (status-code temp-redirect) req
"/" "/")
2002-10-09 11:22:50 -04:00
))
; ))
))