Update: I've made a not exact copy of this page at the p5 wiki (as suggested by Aristotle).

There are many web form processing modules on CPAN - but no one place to compare the features of them. This meditation purpose is to start gathering this comparison information. A wiki page would be more convenient for that - but for now I have no access to some suitable wiki (but as soon as the Catalyst wiki is usable again I'll repost the info there).

I am waiting for suggestions on both how to do this kind of comparison and what to compare. Below is a quick start. I plan to modify this page for a long time.

HTML - HTML generation. It looks like all form processing modules provide validation - so the validation column did not provide any discrimination value and I removed it.
Module name Synopsis HTML Integration with DB
Form::Processor In 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; }
no - but there is a promise of a 'plug-in system' Form::Processor::Model::CDBI
---
HTML::FormFu
use HTML::FormFu; my $form = HTML::FormFu->new; $form->load_config_file('form.yml'); $form->process( $cgi_query ); if ( $form->submitted_and_valid ) { # do something with $form->params } else { # display the form $template->param( form => $form ); }
yes DBIx::Class::HTML::FormFu
---
HTML::Widget now defunct to be replaced by HTML::FormFu above yes HTML::Widget::DBIC
---
CGI::Application::Plugin::ValidateRM This only works with CGI::Application - but Data::FormValidator alone can be used outside of it.
# This is the run mode that will be validated. Notice that it accepts # some errors to be passed in, and on to the template system. sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('page.html'); $t->param($errs) if $errs; return $t->output; } sub form_process { my $self = shift; use CGI::Application::Plugin::ValidateRM (qw/check_rm/); my ($results, $err_page) = $self->check_rm('form_display','_form_pro +file'); return $err_page if $err_page; #.. do something with DFV $results object now my $t = $self->load_tmpl('success.html'); return $t->output; } sub _form_profile { return { required => 'email', msgs => { any_errors => 'some_errors', prefix => 'err_', }, }; }
yes -
---
CGI::FormBuilder
use CGI::FormBuilder; # Assume we did a DBI query to get existing values my $dbval = $sth->fetchrow_hashref; # First create our form my $form = CGI::FormBuilder->new( name => 'acctinfo', method => 'post', stylesheet => '/path/to/style.css', values => $dbval, # defaults ); # Now create form fields, in order # FormBuilder will automatically determine the type for you $form->field(name => 'fname', label => 'First Name'); $form->field(name => 'lname', label => 'Last Name'); # Setup gender field to have options $form->field(name => 'gender', options => [qw(Male Female)] ); # Include validation for the email field $form->field(name => 'email', size => 60, validate => 'EMAIL', required => 1); # And the (optional) phone field $form->field(name => 'phone', size => 10, validate => '/^1?-?\d{3}-?\d{3}-?\d{4}$/', comment => '<i>optional</i>'); # Check to see if we're submitted and valid if ($form->submitted && $form->validate) { # Get form fields as hashref my $field = $form->fields; # Do something to update your data (you would write this) do_data_update($field->{lname}, $field->{fname}, $field->{email}, $field->{phone}, $field->{gender}); # Show confirmation screen print $form->confirm(header => 1); } else { # Print out the form print $form->render(header => 1); }
yes no

Updates: