Tags
There are no tags for this page.
Attachments
Perl 5 Wiki
Form Processing
Overview
Excerpt from the Form::Processor description:
This is a class for working with forms. A form acts as a layer between your internal data representation (such as a database) and the outside world (such as a web form). Moving data between these areas often requires validation and encoding or expanding of the data. For example, a date might be a timestamp internally but externally is a collection of year, month, day, hour, minute input fields.
This is a good outline of the computing task described on this page. Many of the modules also generated an HTML representation of the form, but not all.
As the name suggests Data::FormValidator primary goal is input data validation, but it can also do filtering of that data (with built in filters like 'trim' - for trimming white space, 'lc' etc).
The nice thing about Catalyst::Plugin::Form::Processor is the resulting brevity of the controllers. It's DRY to the extremes - it really abstracts away all the repeatable code:
# Create or edit
sub edit : Local {
my ( $self, $c, $user_id ) = @_;
if ($c->request->method eq 'POST') {
# Validate and insert/update database
$c->response->redirect('/list') if $c->update_from_form( $user_id );
}
}
HTML::FormFu does both the input data processing (filtering, transforming, validating, constraining) and HTML generation. It has a very nice way of creating forms from YAML config files and is fully internationalized.
Rose::HTML::Objects is a framework for creating a resuable set of form and field widgets as mutable Perl objects that can be serialized to HTML or XHTML for display purposes. On the Perl side, these objects are treated as abstract entities that can be fed input and will produce output in the form that is most convenient for the programmer. (E.g., pass a DateTime object to a date picker field to initialize it, and get a DateTime object back from the field when asking for its value).
Fields may be simple (one standard HTML form field to one Perl field object) or compound (a field object that serializes to an arbitrary number of HTML tags, but can be addressed as a single logical field internally). Likewise, forms themselves can be nested.
Each field has its own customizable validation, input filter, output filter, internal value (a plain value or a Perl object, whatever is most convenient), output value (the value shown when the field is redisplayed), label, associated error, and any other metadata deemed necessary. Each field can also be serialized to the equivalent set of (X)HTML "hidden" fields. All HTML attributes are customizable.
All labels, errors, and messages used in the bundled form and field widgets are localized in several languages. An extensible localization framework is provided, allowing new languages to be added and new HTML widgets to have their own localized labels, errors, and messages.
Forms are expected to be initialized with, and return an object or list of objects that the form represents. For example, a registration form could be initialized with and return a UserAccount object.
Users are encouraged to create their own library of reusable form and field widgets for use on their site. A private library creation API is provided to make this as easy as possible. The expectation is that the same kind of field appears in multiple places in any large web application (e.g., username fields, password fields, address forms, etc.) Each field encapsulates a set of values (e.g., options in a pop-up menu), labels, validation constraints, filters, and error messages. Similarly, each form encapsulates a set of fields along with any inter-field validation, error messages, and init-with/object-from methods. Nesting forms and fields preserves this delegation of responsibility, with each higher level having access to its children to perform inter-form/field tasks.
A base set of field objects representing the standard HTML form tags as well as a several examples of compound and other custom fields are included in the distribution. There are also basic init-with/object-from methods for forms.
See the following POD for more information on the most prominent features:
Other resources:
is a new Form Processor (based on Form::Processor) using the Moose object framework. Mailing list: http://groups.google.com/group/formhandler
See also:
Defining the form processing problem
Most of the packages above do three things: parameter transformation, parameter validation and HTML generation, some also interface to the model. It would be nice if we devised APIs for each of those tasks - so that we could split that code into four parts into specialised highly cohesive components.
|