Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2011 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1385592 to your computer and use it in GitHub Desktop.
Save anonymous/1385592 to your computer and use it in GitHub Desktop.
#lang web-server/insta
(require web-server/formlets)
(define record (hasheq 'name "Test User"
'company "Acme Company Inc"
'address "123 Holiday Ave"
'city "New York"
'state "NY"
'zip "12220"))
(define (start request)
(edit-record request))
(define (record-formlet our-values)
(formlet
(#%# ,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'name))))) . => . name}
,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'company))))) . => . company}
,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'address))))) . => . address}
,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'city))))) . => . city}
,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'state))))) . => . state}
,{(to-string (required (text-input #:value (string->bytes/utf-8 (hash-ref our-values 'zip))))) . => . zip})
(values name company address city state zip)))
(define (edit-record request)
(define formlet-container (record-formlet record))
(define (handle-response request)
(define-values (name company address city state zip)
(formlet-process formlet-container request))
(set! record (hasheq 'name name
'company company
'address address
'city city
'state state
'zip zip))
(start (redirect/get)))
(define (response-generator embed/url)
(response/xexpr
`(html
(form ([action ,(embed/url handle-response)])
,@(formlet-display formlet-container)
(input ([type "submit"]))))))
(send/suspend/dispatch response-generator))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment