public
anonymous / gist:1385592
Created

  • Download Gist
gistfile1.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#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))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.