doc.txt

mbform : Multi-buton forms

_mbform : Multi-buton forms_
==========================================

By Jay McCarthy (jay dot mccarthy at gmail dot com)

Keywords: _net_,

_mbform.ss_
-----------

This is the main file for the library. Require it like this:

> (require (planet "mbform.ss" ("jaymccarthy" "mbform.plt" 1)))

It provides the follow procedure:

> (mbform gen) :: ((request -> alpha) ((request -> alpha) -> string) -> beta) -> beta

This function is similar to _send/suspend/dispatch_. It takes a
function that is provided with two functions.

The first, _handle-submit_, should be used with a call to _embed/url_
in the ACTION attribute of the multi-button FORM. This function will
call one of the callbacks registered with the second function.

The second, _add-button!_, is used to allocate a NAME attribute for an
INPUT button. If that button is eventually clicked in a FORM that uses
the aforementioned _handle-submit_ as the ACTION, then the procedure
passed to this call to _add-button!_ will be invoked with the new
_request_.

Example
========

 (define (handle op)
   (lambda (req)
     (define bs (request-bindings req))
     (send/back
      `(html (head (title "Answer"))
             (body
              ,(number->string
                (op (string->number (extract-binding/single 'n1 bs))
                    (string->number (extract-binding/single 'n2 bs)))))))))

 (define (start ireq)
   (send/suspend/dispatch
    (lambda (embed/url)
      `(html (head (title "Test"))
             (body
              ,(mbform
                (lambda (handler add-button!)
                  `(form ([action ,(embed/url handler)])
                         (input ([type "text"] [name "n1"]))
                         (input ([type "text"] [name "n2"]))
                         (input ([type "submit"]
                                 [value "Add"]
                                 [name ,(add-button! (handle +))]))
                         (input ([type "submit"]
                                 [value "Multiply"]
                                 [name ,(add-button! (handle *))]))))))))))