The whofields Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The whofields Reference Manual

This is the whofields Reference Manual, version 0.1.0, generated automatically by Declt version 2.3 "Robert April" on Tue Jan 09 16:01:50 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

whofields

Whofields is an HTML field rendering and input validation utility library written in Common Lisp.

Whofields depends on CL-WHO. Whofields is being developed with SBCL, CCL, and LispWorks on OS X. Whofields is being deployed with SBCL on Linux/AMD64.

Field Specifiers

Whofields defines the notion of a field specifier--a fieldspec--to specify the name, label, and control-specific properties of a field. Whofields currently supports :TEXT, :PASSWORD, :SELECT, :RADIO, and :CHECKBOX fieldspecs.

Whofields provides functions for rendering HTML form controls and for validating HTTP POST and GET parameter values according to fieldspecs. However, Whofields makes no assumptions about the means of obtaining HTTP parameters; Whofields accepts either single values or alists of parameter names and values.

Installation

(ql:quickload "whofields")

Example


(defun parse-string (x)
  (if (stringp x)
      (values (string-trim '(#\Space #\Tab #\Newline) x) t)
      (values nil nil)))

(defun parse-non-empty-string (x)
  (if (stringp x)
      (let ((x (string-trim '(#\Space #\Tab #\Newline) x)))
        (if (string/= "" x)
            (values x t)
            (values nil nil)))
      (values nil nil)))

(defparameter *provinces*
  '(("AB" . "Alberta)
    ("BC" . "British Columbia")
    ("MB" . "Manitoba")
    ("NB" . "New Brunswick")
    ("NL" . "Newfoundland and Labrador")
    ("NT" . "Northwest Territories")
    ("NS" . "Nova Scotia")
    ("NU" . "Nunavut")
    ("ON" . "Ontario")
    ("PE" . "Prince Edward Island")
    ("QC" . "Quebec")
    ("SK" . "Saskatchewan")
    ("YT" . "Yukon")))

(defparameter *registration-fieldspecs*
  (list (list 'username :text :label "Corporation" :validation-function #'parse-non-empty-string
              :placeholder "Corporation")
        (list 'full-name :text :label "Full Name" :validation-function #'parse-non-empty-string
              :placeholder "Full Name")
        (list 'email :text :label "Email" :validation-function #'parse-non-empty-string
               :placeholder "Email")
        (list 'email2 :text :label "Email (confirm)" :validation-function #'parse-non-empty-string
              :placeholder "Email (confirm)")
        (list 'phone :text :label "Phone" :validation-function #'parse-non-empty-string
              :placeholder "Phone")
        (list 'alt-phone :text :label "Alt. Phone" :validation-function #'parse-string
              :placeholder "Alt. Phone")
        (list 'address :text :label "Address" :validation-function #'parse-non-empty-string
              :placeholder "Address")
        (list 'city :text :label "City" :validation-function #'parse-non-empty-string
              :placeholder "City")
        (list 'province :select :label "Province"
              :options *provinces* :key #'car :label-function #'cdr :test #'string=)
        (list 'postal-code :text :label "Postal Code" :validation-function #'parse-non-empty-string
              :placeholder "Postal Code")
        (list 'agrees-to-mailing-list :label "I want to join the mailing list" :checkbox :truep t)))

(defparameter *registration-fieldvals*
  (list (cons 'username "")
        (cons 'full-name "")
        (cons 'email "")
        (cons 'email2 "")
        (cons 'phone "")
        (cons 'alt-phone "")
        (cons 'address "")
        (cons 'city "")
        (cons 'province "ON")
        (cons 'postal-code "")
        (cons 'agrees-to-mailing-list nil)))

(defun render-registration-page (fieldvals fielderrs &optional (stream *standard-output*))
  (with-html-page (stream)
    (:div :class "container"
          (when fielderrs
           (cl-who:htm
             (:div :class "alert alert-danger" "Please correct the issues highlighted below.")))
         (:form :action "/registration" :method "post"
                (dolist (fieldspec *registration-fieldspecs*)
                  (let ((name (whofields/core:fieldspec-name fieldspec))
                        (label (whofields/core:fieldspec-label fieldspec)))
                    (cl-who:htm
                     (:div :class (if (member name fielderrs) "form-group has-error" "form-group")
                           (:label :for (string-downcase name) :class "control-label col-sm-2"
                                   (cl-who:esc label))
                           (:div :class "col-sm-10"
                                 (whofields/core:render-field stream
                                                              fieldspec
                                                              (cdr (assoc name fieldvals))))))))
                (:div :class "form-group"
                      (:div :class "col-sm-12"
                            (:button :type "submit" :class "btn btn-primary" "Register")))))))

(hunchentoot:define-easy-handler (handle-registration :uri (princ-to-string "/registration"))
    ()
  (setf (hunchentoot:content-type*) "text/html; charset=utf-8")
  (cond ((equal (hunchentoot:request-method*) :post)
         (multiple-value-bind (fieldvals fielderrs)
             (whofields/core:validate-fields *registration-fieldspecs*
                                             (hunchentoot:post-parameters*))
           (unless (string= (hunchentoot:post-parameter "email")
                            (hunchentoot:post-parameter "email2"))
             (push 'email2 fielderrs))
           (if fielderrs
               (with-output-to-string (stream)
                 (render-registration-page fieldvals fielderrs stream))
               (progn
                 (model:register fieldvals)
                 (hunchentoot:redirect "/registration-complete")))))
        ((equal (hunchentoot:request-method*) :get)
         (with-output-to-string (stream)
           (render-registration-page *registration-fieldvals* '() stream)))))

License

Whofields is distributed under the MIT license. See LICENSE.


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Next: , Previous: , Up: Systems   [Contents][Index]

2.1 whofields

Author

Michael J. Forster <mike@forsterfamily.ca>

License

MIT

Description

HTML field rendering and input validation utilities written in Common Lisp

Version

0.1.0

Defsystem Dependency

asdf-package-system

Dependency

whofields/core/all (system)

Source

whofields.asd (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.2 whofields/core/all

Dependencies
Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.3 whofields/core/render

Dependency

cl-who

Component

lisp.lisp (file)


Next: , Previous: , Up: Systems   [Contents][Index]

2.4 whofields/core/validate

Dependency

whofields/core/fieldspec (system)

Component

lisp.lisp (file)


Previous: , Up: Systems   [Contents][Index]

2.5 whofields/core/fieldspec

Component

lisp.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 whofields.asd

Location

whofields.asd

Systems

whofields (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 whofields/core/all/lisp.lisp

Parent

whofields/core/all (system)

Location

core/all.lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.3 whofields/core/render/lisp.lisp

Parent

whofields/core/render (system)

Location

core/render.lisp

Packages

whofields/core/render

Exported Definitions

render-field (function)

Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.4 whofields/core/validate/lisp.lisp

Parent

whofields/core/validate (system)

Location

core/validate.lisp

Packages

whofields/core/validate

Exported Definitions
Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

3.1.5 whofields/core/fieldspec/lisp.lisp

Parent

whofields/core/fieldspec (system)

Location

core/fieldspec.lisp

Packages

whofields/core/fieldspec

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 whofields/core/render

Source

lisp.lisp (file)

Use List

common-lisp

Used By List

whofields/core/all

Exported Definitions

render-field (function)

Internal Definitions

Next: , Previous: , Up: Packages   [Contents][Index]

4.2 whofields/core/validate

Source

lisp.lisp (file)

Use List

common-lisp

Used By List

whofields/core/all

Exported Definitions
Internal Definitions

Previous: , Up: Packages   [Contents][Index]

4.3 whofields/core/fieldspec

Source

lisp.lisp (file)

Use List

common-lisp

Used By List

whofields/core/all

Exported Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Functions

Function: fieldspec-label FIELDSPEC
Package

whofields/core/fieldspec

Source

lisp.lisp (file)

Function: fieldspec-name FIELDSPEC
Package

whofields/core/fieldspec

Source

lisp.lisp (file)

Function: fieldspec-plist FIELDSPEC
Package

whofields/core/fieldspec

Source

lisp.lisp (file)

Function: render-field STREAM FIELDSPEC VALUE
Package

whofields/core/render

Source

lisp.lisp (file)

Function: validate-field FIELDSPEC VALUE
Package

whofields/core/validate

Source

lisp.lisp (file)

Function: validate-fields FIELDSPECS FIELDVALS
Package

whofields/core/validate

Source

lisp.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Functions

Function: escape-value VALUE
Package

whofields/core/render

Source

lisp.lisp (file)

Function: render-checkbox STREAM NAME VALUE &key &allow-other-keys
Package

whofields/core/render

Source

lisp.lisp (file)

Function: render-password-input STREAM NAME VALUE &key PLACEHOLDER &allow-other-keys
Package

whofields/core/render

Source

lisp.lisp (file)

Function: render-select STREAM NAME VALUE &key OPTIONS TEST KEY LABEL-FUNCTION &allow-other-keys
Package

whofields/core/render

Source

lisp.lisp (file)

Function: render-static STREAM NAME VALUE &key &allow-other-keys
Package

whofields/core/render

Source

lisp.lisp (file)

Function: render-text-input STREAM NAME VALUE &key PLACEHOLDER &allow-other-keys
Package

whofields/core/render

Source

lisp.lisp (file)

Function: validate-boolean VALUE &key TRUEP &allow-other-keys
Package

whofields/core/validate

Source

lisp.lisp (file)

Function: validate-option VALUE &key OPTIONS TEST KEY &allow-other-keys
Package

whofields/core/validate

Source

lisp.lisp (file)

Function: validate-string VALUE &key VALIDATION-FUNCTION &allow-other-keys
Package

whofields/core/validate

Source

lisp.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   L   W  
Index Entry  Section

F
File, Lisp, whofields.asd: The whofields<dot>asd file
File, Lisp, whofields/core/all/lisp.lisp: The whofields/core/all/lisp<dot>lisp file
File, Lisp, whofields/core/fieldspec/lisp.lisp: The whofields/core/fieldspec/lisp<dot>lisp file
File, Lisp, whofields/core/render/lisp.lisp: The whofields/core/render/lisp<dot>lisp file
File, Lisp, whofields/core/validate/lisp.lisp: The whofields/core/validate/lisp<dot>lisp file

L
Lisp File, whofields.asd: The whofields<dot>asd file
Lisp File, whofields/core/all/lisp.lisp: The whofields/core/all/lisp<dot>lisp file
Lisp File, whofields/core/fieldspec/lisp.lisp: The whofields/core/fieldspec/lisp<dot>lisp file
Lisp File, whofields/core/render/lisp.lisp: The whofields/core/render/lisp<dot>lisp file
Lisp File, whofields/core/validate/lisp.lisp: The whofields/core/validate/lisp<dot>lisp file

W
whofields.asd: The whofields<dot>asd file
whofields/core/all/lisp.lisp: The whofields/core/all/lisp<dot>lisp file
whofields/core/fieldspec/lisp.lisp: The whofields/core/fieldspec/lisp<dot>lisp file
whofields/core/render/lisp.lisp: The whofields/core/render/lisp<dot>lisp file
whofields/core/validate/lisp.lisp: The whofields/core/validate/lisp<dot>lisp file

Jump to:   F   L   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   E   F   R   V  
Index Entry  Section

E
escape-value: Internal functions

F
fieldspec-label: Exported functions
fieldspec-name: Exported functions
fieldspec-plist: Exported functions
Function, escape-value: Internal functions
Function, fieldspec-label: Exported functions
Function, fieldspec-name: Exported functions
Function, fieldspec-plist: Exported functions
Function, render-checkbox: Internal functions
Function, render-field: Exported functions
Function, render-password-input: Internal functions
Function, render-select: Internal functions
Function, render-static: Internal functions
Function, render-text-input: Internal functions
Function, validate-boolean: Internal functions
Function, validate-field: Exported functions
Function, validate-fields: Exported functions
Function, validate-option: Internal functions
Function, validate-string: Internal functions

R
render-checkbox: Internal functions
render-field: Exported functions
render-password-input: Internal functions
render-select: Internal functions
render-static: Internal functions
render-text-input: Internal functions

V
validate-boolean: Internal functions
validate-field: Exported functions
validate-fields: Exported functions
validate-option: Internal functions
validate-string: Internal functions

Jump to:   E   F   R   V  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   P   S   W  
Index Entry  Section

P
Package, whofields/core/fieldspec: The whofields/core/fieldspec package
Package, whofields/core/render: The whofields/core/render package
Package, whofields/core/validate: The whofields/core/validate package

S
System, whofields: The whofields system
System, whofields/core/all: The whofields/core/all system
System, whofields/core/fieldspec: The whofields/core/fieldspec system
System, whofields/core/render: The whofields/core/render system
System, whofields/core/validate: The whofields/core/validate system

W
whofields: The whofields system
whofields/core/all: The whofields/core/all system
whofields/core/fieldspec: The whofields/core/fieldspec system
whofields/core/fieldspec: The whofields/core/fieldspec package
whofields/core/render: The whofields/core/render system
whofields/core/render: The whofields/core/render package
whofields/core/validate: The whofields/core/validate system
whofields/core/validate: The whofields/core/validate package

Jump to:   P   S   W