Making change suggested by Norman Gray

This commit is contained in:
Jay McCarthy 2012-02-20 10:50:33 -07:00
parent 75a326e027
commit 1b054eed1b
6 changed files with 84 additions and 9 deletions

View File

@ -75,7 +75,11 @@
(test-add-two-numbers mkd "add-compat0.rkt"
(build-path example-servlets "add-compat0.rkt"))
(test-add-two-numbers mkd "add-formlets.rkt - send/formlet"
(build-path example-servlets "add-formlets.rkt"))
(build-path example-servlets "add-formlets0.rkt"))
(test-add-two-numbers mkd "add-formlets.rkt - send/formlet, get"
(build-path example-servlets "add-formlets1.rkt"))
(test-add-two-numbers mkd "add-formlets.rkt - send/formlet, post"
(build-path example-servlets "add-formlets2.rkt"))
(test-add-two-numbers mkd "add-page.rkt"
(build-path example-servlets "add-page.rkt"))
(test-equal? "count.rkt - state"

View File

@ -0,0 +1,29 @@
#lang racket
(require web-server/servlet
web-server/formlets)
(provide (all-defined-out))
(define interface-version 'v1)
(define timeout +inf.0)
; request-number : str -> num
(define (request-number which-number)
(send/formlet
(formlet
(#%# "Enter the " ,which-number " number to add: "
,{input-int . => . the-number}
(input ([type "submit"] [name "enter"] [value "Enter"])))
the-number)
#:method
"GET"
#:wrap
(lambda (f-expr)
`(html (head (title "Enter a Number to Add"))
(body ([bgcolor "white"])
,f-expr)))))
(define (start initial-request)
(response/xexpr
`(html (head (title "Sum"))
(body ([bgcolor "white"])
(p "The answer is "
,(number->string (+ (request-number "first") (request-number "second"))))))))

View File

@ -0,0 +1,29 @@
#lang racket
(require web-server/servlet
web-server/formlets)
(provide (all-defined-out))
(define interface-version 'v1)
(define timeout +inf.0)
; request-number : str -> num
(define (request-number which-number)
(send/formlet
(formlet
(#%# "Enter the " ,which-number " number to add: "
,{input-int . => . the-number}
(input ([type "submit"] [name "enter"] [value "Enter"])))
the-number)
#:method
"POST"
#:wrap
(lambda (f-expr)
`(html (head (title "Enter a Number to Add"))
(body ([bgcolor "white"])
,f-expr)))))
(define (start initial-request)
(response/xexpr
`(html (head (title "Sum"))
(body ([bgcolor "white"])
(p "The answer is "
,(number->string (+ (request-number "first") (request-number "second"))))))))

View File

@ -5,10 +5,14 @@
(provide/contract
[send/formlet ((formlet*/c)
(#:wrap (pretty-xexpr/c . -> . pretty-xexpr/c))
. ->* . any)])
(#:method (or/c "GET" "POST" "get" "post")
#:wrap (pretty-xexpr/c . -> . pretty-xexpr/c))
. ->* .
any)])
(define (send/formlet f
#:method
[method "POST"]
#:wrap
[wrapper
(lambda (form-xexpr)
@ -20,11 +24,15 @@
(lambda (k-url)
(response/xexpr
(wrapper
`(form ([action ,k-url])
`(form ([action ,k-url] [method ,method])
,@(formlet-display f))))))))
(provide/contract
[embed-formlet (((request? . -> . any) . -> . string?) formlet*/c . -> . pretty-xexpr/c)])
[embed-formlet
(((request? . -> . any) . -> . string?)
formlet*/c
. -> .
pretty-xexpr/c)])
(define (embed-formlet embed/url f)
`(form ([action ,(embed/url

View File

@ -502,17 +502,22 @@ a list of elements of the sequence.
A few utilities are provided for using @tech{formlet}s in Web applications.
@defproc[(send/formlet [f (formlet/c any/c ...)]
[#:method method
(or/c "GET" "POST" "get" "post")
"POST"]
[#:wrap wrapper
(xexpr/c . -> . xexpr/c)
(lambda (form-xexpr)
`(html (head (title "Form Entry"))
(body ,form-xexpr)))])
(values any/c ...)]{
Uses @racket[send/suspend] and @racket[response/xexpr] to send
@racket[f]'s rendering (wrapped in a FORM tag whose action is the
continuation URL (wrapped again by @racket[wrapper])) to the client.
When the form is submitted, the request is passed to the processing
stage of @racket[f].
@racket[f]'s rendering (wrapped in a FORM tag with method
@racket[method] whose action is the continuation URL (wrapped again
by @racket[wrapper])) to the client. When the form is submitted,
the request is passed to the processing stage of @racket[f].
}
@defproc[(embed-formlet [embed/url ((request? . -> . any) . -> . string?)]