HTML::FormHandler

HTML forms using Moose
Download

HTML::FormHandler Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Gerda Shank
  • Publisher web site:
  • http://search.cpan.org/~gshank/

HTML::FormHandler Tags


HTML::FormHandler Description

HTML::FormHandler is a Perl module that maintains a clean separation between form construction and form rendering. It allows you to define your forms and fields in a number of flexible ways. Although it provides renderers for HTML, you can define custom renderers for any kind of presentation.HTML::FormHandler allows you to define form fields and validators. It can be used for both database and non-database forms, and will automatically update or create rows in a database. It can be used to process structured data that doesn't come from an HTML form.One of its goals is to keep the controller/application program interface as simple as possible, and to minimize the duplication of code. In most cases, interfacing your controller to your form is only a few lines of code.With FormHandler you shouldn't have to spend hours trying to figure out how to make a simple HTML change that would take one minute by hand. Because you _can_ do it by hand. Or you can automate HTML generation as much as you want, with template widgets or pure Perl rendering classes, and stay completely in control of what, where, and how much is done automatically. You can define custom renderers and display your rendered forms however you want.You can split the pieces of your forms up into logical parts and compose complete forms from FormHandler classes, roles, fields, collections of validations, transformations and Moose type constraints. You can write custom methods to process forms, add any attribute you like, use Moose method modifiers. FormHandler forms are Perl classes, so there's a lot of flexibility in what you can do.HTML::FormHandler provides rendering through roles which are applied to form and field classes (although there's no reason you couldn't write a renderer as an external object either). There are currently two flavors: all-in-one solutions like HTML::FormHandler::Render::Simple and HTML::FormHandler::Render::Table that contain methods for rendering field widget classes, and the HTML::FormHandler::Widget roles, which are more atomic roles which are automatically applied to fields and form. See HTML::FormHandler::Manual::Rendering for more details. (And you can easily use hand-build forms - FormHandler doesn't care.)The typical application for FormHandler would be in a Catalyst, DBIx::Class, Template Toolkit web application, but use is not limited to that. FormHandler can be used in any Perl application.More Formhandler documentation and a tutorial can be found in the manual at HTML::FormHandler::Manual.SYNOPSISSee the manual at " HTML::FormHandler::Manual ". use HTML::FormHandler; # or a custom form: use MyApp::Form::User; my $form = HTML::FormHandler->new( .... ); $form->process( params => $params ); my $rendered_form = $form->render; if( $form->validated ) { # perform validated form actions } else { # perform non-validated actions }Or, if you want to use a form 'result' (which contains only the form values and error messages) instead: use MyApp::Form; # or a generic form: use HTML::FormHandler; my $form = MyApp::Form->new( .... ); my $result = $form->run( params => $params ); if( $result->validated ) { # perform validated form actions } else { # perform non-validated actions $result->render; }An example of a custom form class: package MyApp::Form::User; use HTML::FormHandler::Moose; extends 'HTML::FormHandler'; use Moose::Util::TypeConstraints; has '+item_class' => ( default => 'User' ); has_field 'name' => ( type => 'Text' ); has_field 'age' => ( type => 'PosInteger', apply => ); has_field 'birthdate' => ( type => 'DateTime' ); has_field 'birthdate.month' => ( type => 'Month' ); has_field 'birthdate.day' => ( type => 'MonthDay' ); has_field 'birthdate.year' => ( type => 'Year' ); has_field 'hobbies' => ( type => 'Multiple' ); has_field 'address' => ( type => 'Text' ); has_field 'city' => ( type => 'Text' ); has_field 'state' => ( type => 'Select' ); has_field 'email' => ( type => 'Email' ); has '+dependency' => ( default => sub { , ] } ); subtype 'MinimumAge' => as 'Int' => where { $_ > 13 } => message { "You are not old enough to register" }; no HTML::FormHandler::Moose; 1;A dynamic form - one that does not use a custom form class - may be created using the 'field_list' attribute to set fields: my $form = HTML::FormHandler->new( name => 'user_form', item => $user, field_list => */, message => 'Contains invalid characters' } ], }, 'select_bar' => { type => 'Select', options => \@select_options, multiple => 1, size => 4, }, ], );FormHandler does not provide a custom controller for Catalyst because it isn't necessary. Interfacing to FormHandler is only a couple of lines of code. See HTML::FormHandler::Manual::Catalyst for more details, or Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormHandler.Product's homepage


HTML::FormHandler Related Software