Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:1385592
Created Nov 22, 2011

What would you like to do?
#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)
(#%# ,{(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)
(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