Skip to content

anonymous /gist:1385592
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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
Something went wrong with that request. Please try again.