[racket] formlet checkbox behaves differently from others

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Jun 16 16:27:21 EDT 2014

Most core formlets return binding structures. Your formlet uses
input-int and input-string, which are short-hands. For instance,
input-string is (to-string (required (text-input))) [1]. In contrast,
checkbox is core, so if you look at its documentation [2] you can see
the return type is, (formlet/c (or/c false/c binding?)). It looks like
you want (to-string (require (checkbox ...)))

Jay

1. http://docs.racket-lang.org/web-server/formlets.html#%28def._%28%28lib._web-server%2Fformlets%2Finput..rkt%29._input-string%29%29
2. http://docs.racket-lang.org/web-server/formlets.html#%28def._%28%28lib._web-server%2Fformlets%2Finput..rkt%29._checkbox%29%29

On Sat, Jun 14, 2014 at 6:38 AM, J G Cho <gcho at fundingmatters.com> wrote:
> Here is my code:
>
> #lang web-server/insta
>
> (require web-server/formlets)
>
> (define (start request)
>   (define answer (get-answer "Formlet"))
>   (response/xexpr
>    `(html (head (title "formlet"))
>           (body "Answer: " ,(format "~a" answer)))))
>
> (define date-formlet
>   (formlet
>    (div "Month:" ,{input-int . => . month}
>         "Day:"   ,{input-int . => . day})
>    (list month day)))
>
> (define travel-formlet
>   (formlet
>    (div "Name:" ,(input-string . => . name)
>         (div "Depart:" ,{date-formlet . => . depart}
>              "Return:" ,{date-formlet . => . return})
>         (div "Car:" ,((select-input (list "No" "Avis" "Budget" "Hertz"))
>                       . => . car))
>         (div "Hotel:"  ,((checkbox "hotel" #f)
>                          . => . hotel)))
>    (list name depart return car hotel)))
>
> (define my-formlet
>   travel-formlet)
>
> (define (get-answer label)
>   (formlet-process my-formlet
>                    (send/suspend
>                     (λ (k-url)
>                       (response/xexpr
>                        `(html (head (title ,label))
>                               (body
>                                (form ([action ,k-url])
>                                      ,@(formlet-display my-formlet)
>                                      (input ([type "submit"])) ))))))))
>
>
> I fill in the form and then I get the following:
>
> Answer: (jon do (7 4) (7 21) Avis #(struct:binding:form input_6 hotel))
>
> I sorta expected to see "hotel" here but I get the struct instead. Why is
> this so?
>
> Thanks in advance.
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33


Posted on the users mailing list.