Form::Processor

Form::Processor is a Perl module that can validate and process form data.
Download

Form::Processor Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Bill Moseley
  • Publisher web site:
  • http://search.cpan.org/~hank/

Form::Processor Tags


Form::Processor Description

Form::Processor is a Perl module that can validate and process form data. Form::Processor is a Perl module that can validate and process form data.SYNOPSISIn an application you might want a controller to handle creating and updating a "User" record. And not want to write much code. Here's using Catalyst as an example: package MyApplication::Controller::User; use strict; use MyApplication::Form::User; sub edit : Local { my ( $self, $c, $id ) = @_; # Create the form object my $form = MyApplication::Form::User->new( $id ); # Update or create the user record if form posted and form validates $form->update_from_from( $c->request->parameters ) if $c->form_posted; $c->stash->{form} = $form; }The above form class might then look like this: package MyApplication::Form::User; use strict; use base 'Form::Processor::Model::CDBI'; sub object_class { 'DB::User' } sub profile { my $self = shift; return { required => { name => 'Text', age => 'PosInteger', sex => 'Select', birthdate => 'DateTimeDMYHM', }, optional => { hobbies => 'Multiple', address => 'Text', city => 'Text', state => 'Select', email => 'Email', }, dependency => , ], }; } sub options_sex { return ( m => 'Male', f => 'Female', ); } sub validate_age { my ( $self, $field ) = @_; $field->add_error('Sorry, you must be 18') if $field->value < 18; }Or when you need a quick, small form do this in a controller: my @fields = qw/ first_name last_name email /; $c->stash->{form} = Form::Processor->new( profile => { required => { map { $_ => 'Text' } qw/ first_name last_name email /, }, }, );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.A form is made up of a collection of fields of possibly different types (e.g. Text, Email, Integer, Date), where the fields require validation before being accepted into their internal format. The validation process is really made up of a number of steps, where each step can be overridden to customize the process. See Form::Processor::Field for methods specific to fields.Forms are (typically) defined by creating a separate Perl module that includes methods for defining the fields that make up the form, plus any special and additional validation checks on the fields.Form::Processor does not generate any HTML. HTML should be generated in a "view" (and often using templates). And besides, HTML forms are trivial to create and in real life almost always needs customization. The use of a good template system makes this nearly painless.Likewise, there is also no method to spit out an entire web form with a single method. Having a single method to generate a complete HTML form is often only useful for the most simple web forms.This module is not restricted to use in a web environment, although that is the typical application. It was designed for use with Catalyst, Class::DBI, Template-Toolkit, and HTML::FillInForm. But, those are not required.The design of this class is based a lot on the design of Rose::HTML::Objects, but, as mentioned, HTML widget generation is not part of the class. This class focuses more on moving data between the data store to the form that from the form to html. It's recommended that you look over Rose::HTML::Objects if not already done so. Requirements: · Perl


Form::Processor Related Software