Home

Awesome

CL-FORMS

CL-FORMS is a web forms handling library for Common Lisp.

Although it is potentially framework agnostic, it runs on top of Hunchentoot at the moment.

It features:

Basics

Use defform to define a form. Example:

(defform fields-form (:action "/fields-post")
  ((name :string :value "")
   (ready :boolean :value t)
   (sex :choice :choices (list "Male" "Female") :value "Male")
   (submit :submit :label "Create")))

On your web handler, grab the form via find-form, select a renderer with with-form-rendererand then render the form with render-form:

(let ((form (forms::find-form 'fields-form)))
   (forms:with-form-renderer :who
      (forms:render-form form))

To handle the form, grab it via find-form and then call handle-request (you should probably also call validate-form after). Then bind form fields via either with-form-field-values, that binds the form field values; or with-form-fields that binds the form fields.

(let ((form (forms:find-form 'fields-form)))
    (forms::handle-request form)
    (forms::with-form-field-values (name ready sex) form
       (who:with-html-output (forms.who::*html*)
          (:ul
            (:li (who:fmt "Name: ~A" name))
            (:li (who:fmt "Ready: ~A" ready))
            (:li (who:fmt "Sex: ~A" sex))))))

Plase have a look at the demo sources for more examples of how to use the library

DEMO

There's a demo included. To run:

(require :cl-forms.demo)
(forms.test:run-demo)