V
42  

del.icio.us icon Bookmark this page

Edit the sidebar

Tags
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.

Module Name Catalyst CGI::Application Database HTML Config
CGI::FormBuilder Catalyst::Controller::FormBuilder        
Data::FormValidator Catalyst::Plugin::FormValidator CGI::Application::Plugin::ValidateRM   no  
Form::Processor Catalyst::Plugin::Form::Processor  

Form::Processor::Model::CDBI
Form::Processor::Model::DOD
Form::Processor::Model::DBIC

no yet no
HTML::FormFu Catalyst::Controller::HTML::FormFu  

HTML::FormFu::Model::DBIC
(DBIx::Class::HTML::FormFu is deprecated)

yes yes
Rose::HTML::Objects       yes  
HTML::FormHandler    

HTML::FormHandler::Model::CDBI
HTML::FormHandler::Model::DBIC

experimental  

Data::FormValidator

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).

Form::Processor

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

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

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:

HTML::FormHandler

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

Cohesion Discussion

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.


 

Upload Files

Click "Browse" to find the file you want to upload. When you click "Upload file" your file will be uploaded and added to the list of attachments for this page.

Maximum file size: 50MB

 
 
 
File Name Author Date Uploaded Size

Save Page As

Enter a meaningful and distinctive title for your page.

Page Title:

Tip: You'll be able to find this page later by using the title you choose.

Page Already Exists

There is already a page named XXX. Would you like to:

Save with a different name:

Save the page with the name "XXX"

Append your text to the bottom of the existing page named: "XXX"

Upload Files

Click "Browse" to find the file you want to upload. When you click "Add file" this file will be added to the list of attachments for this page, and uploaded when you save the page.

 
 
 
Add Tags

Enter a tag and click "Add tag". The tag will be saved when you save the page.

Tag: 

Suggestions: