Git Product home page Git Product logo

cl-forms's Introduction

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:

  • Several form field types: String, boolean, integer, email, password fields. And more.
  • Custom fields. CL-FORMS is extensible and it is possible to define new field types.
  • Server and client side validation
  • Rendering backends. Forms can be rendered via CL-WHO, or Djula, or something else; the backend is pluggable. The default renderer is CL-WHO.
  • Themes (like Bootstrap)
  • Control on rendering and layout.
  • Handling of form errors.
  • CSRF protection

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 get-form, select a renderer with with-form-rendererand then render the form with render-form:

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

To handle the form, grab it via get-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:get-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:

Download web assets. From /test/static directory run:

bower install

and then:

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.