NAME
HTML::FormFu::Manual::BasicConcepts - HTML::FormFu Manual Chapter I - Basic Concepts
VERSION
version 0.002
THE DIFFERENT ASPECTS OF FORM PROCESSING
There are several aspects of form processing, and there are multiple modules on CPAN to handle each of them:
- Generating forms
-
Form generation involves producing the HTML markup for forms from some kind of configuration files, in order to spare the web developer the effort of writing the same html code over and over.
- Filling in forms
-
Modules such as HTML::FillInForm help inject data into an existing HTML form. This help for example when you want to redisplay the information in a form with errors.
- Validating forms
-
There are a number of modules on CPAN that help validate forms, i.e. check that the user has entered acceptable information.
- Error display
-
Hand in hand with validation, an important aspect of form processing is the ability to display to the user proper error messages, highlighting the problematic field, whenever there were problems with the provided input.
- Form submission
-
Last but not least, there are (currently) two libraries on CPAN, namely HTML::FormFu and HTML::FormHandler that have extensions allowing you to automatically save the data entered via the form in a data store, such as a database.
BUILDING BLOCKS OF HTML::FormFu
Elements
Elements are the individual user interface items that comprise a form - input fields, buttons, etc. Elements fall into the following general categories:
- Simple form elements
-
These are for example buttons, text fields, checkboxes, etc. See ""CORE FORM FIELD"S" in HTML::FormFu::Element for a complete list of these.
- Derived form elements
-
These are custom-made form fields based on existing HTML elements (e.g. a date field, or a number field).
- HTML markup elements
-
There are other a number of elements that you can use to insert HTML code other than input fields. These are:
- HTML::FormFu::Element::Label
-
An HTML label element.
- HTML::FormFu::Element::Fieldset
-
An HTML fieldset.
- HTML::FormFu::Element::SimpleTable
-
An element which allows you to format your form using a table (rather than divs).
- HTML::FormFu::Element::Hr
-
An HTML horizontal rule.
- HTML::FormFu::Element::Src
-
An element which allows you to insert arbitrary HTML code within the form.
- Grouping elements
-
These are elements which are designed to contain other elements.
- HTML::FormFu::Element::Block
-
A block element is used to separate logically a given group of elements. For example, a fieldset is a type of a block element.
- HTML::FormFu::Element::Repeatable
-
A repeatable element is used to display a list of items whose number is variable. For example, if you have a form which displays a list of todos, a repeatable element may be used to display the todo items.
- HTML::FormFu::Element::Multi
-
A multi element is used to create a single form element comprising several individual form fields. For example, a date field may comprise of three individual input boxes, for date, month and year. Multi elements are often used in conjunction with inflators and deflators (see below).
Form validation
All of these are components of HTML::FormFu's data validation framework. They work in the following order:
- Filters
-
Filters are used to perform data cleanup before any actual validation is performed. They do things such as trimming whitespace, performing HTML escaping, normalizing numbers, etc. Filters are also used to join the values of the individual fields within a multi element into a single string which is then passed on for processing (see HTML::FormFu::Filter::CompoundJoin and HTML::FormFu::Filter::CompoundSprintf).
- Constraints
-
Constraints do the bulk of the work that is commonly associated with form validation. They define rules that a submitted value must match in order to be considered acceptable. There are constrains to check that a given field is required, that it matches a certain regex, that it is of a certain length, that an uploaded file does not exceed a specified size, that an email address is valid, etc.
- Inflators
-
Inflators allow you to coerce a given field value into an object so that it is easier to work with. A common use of an inflator would be to convert the value of a field representing a date into a DateTime object.
- Validators
-
Validators exist in order to allow you to create validation rules that are specific to the logic and state of your application and cannot be applied at constraint level. For example, if you have a registration form that allows users to use their an address as a username, you would use a constraint to check that the email is valid, but you would use a validator to check if this email does not already exist in the database, and display an error if it does. HTML::FormFu does not come with any validators - since they are always application specific you have to create your own validators by subclassing HTML::FormFu::Validator.
Models
Models are one of the most powerful aspects of HTML::FormFu. They allow you to link to a specified data store and update it automatically when the form receives valid input. Currently HTML::FormFu has the following models:
- HTML::FormFu::Model::DBIC
-
HTML::FormFu::Model::DBIC allows you to link a form with a DBIx::Class::Row object, so that you can load default values into the form from this object, or update it with the submitted form information.
- HTML::FormFu::Model::HashRef
-
HTML::FormFu::Model::HashRef is a simple module that allows you to load data into a form from a hashref, or load submitted form values into a hashref. This module is a good starting point if you want to link an unsupported data source to HTML::FormFu.
AUTHOR
Peter Shangov <pshangov@yahoo.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Peter Shangov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.