[racket] formlet-fill
I have a pattern of user interaction that is common in my web app:
I have a db record, I present it to the user in a form, the user edits
the form, submits it, server side logic validates it, and then returns
the same form with the updated record.
I want to port the app to Racket, and I thought formlets would be just
the thing, but I don't see how to fill the values into the formlet
without making a new formlet... seems I need a (formlet-fill
(some-values)) to go along with the formlet-display and formlet-process.
Here is what I have: (Which doesn't work)
----------------------------------------------------------------------
#lang web-server/insta
(require web-server/formlets)
(define record (hasheq 'title "this is a title"
'body "post body"))
(define (start request)
(edit-record request))
(define (edit-record request)
(local [(define (record-formlet our-values)
(formlet
(#%# ,{(text-input #:value (string->bytes/utf-8 (hash-ref our-values 'title))) . => . title}
,{(text-input #:value (string->bytes/utf-8 (hash-ref our-values 'body))) . => . body})
(values title body)))
(define (handle-response request)
(define-values (title body)
(formlet-process our-formlet request))
(set! record (hasheq 'title title
'body body))
(start (redirect/get)))
(define (response-generator embed/url)
(response/xexpr
`(html
(form ([action ,(embed/url handle-response)])
,@(formlet-display our-formlet)
(input ([type "submit"]))))))]
(send/suspend/dispatch response-generator)))
----------------------------------------------------------------------
It seems like this would be a very common pattern... what is the "normal"
way to do it?
Thanks,
Jordan