NAME CGI::Application::Plugin::ValidateRM - Help validate CGI::Application run modes using Data::FormValidator SYNOPSIS use CGI::Application::Plugin::ValidateRM (qw/check_rm/); my ($results,$err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; # Optionally, you can pass additional options to HTML::FillInForm->fill() my ($results,$err_page) = $self->check_rm('form_display','_form_profile', { fill_password => 0 }); return $err_page if $err_page; DESCRIPTION CGI::Application::Plugin::ValidateRM helps to validate web forms when using the CGI::Application framework and the Data::FormValidator module. check_rm This CGI::Application method takes three inputs and returns two outputs. Its return values are a Data::FormValidator::Results object and, if any fields defined in the profile are missing or invalid, an error page. The inputs are as follows: Return run mode This run mode will be used to generate an error page, with the form re-filled (using HTML::FillInForm) and error messages in the form. This page will be returned as a second output parameter. The errors will be passed in as a hash reference, which can then be handed to a templating system for display. The fields should be prepared using Data::FormValidator's built-in support for returning error messages as a hash reference. See the documentation for "msgs" in the Data::FormValidator::Results documentation. Returning the errors with a prefix, such as "err_" is recommended. Using "any_errors" is also recommended to make it easy to display a general "we have some errors" message. HTML::Template users may want to pass "die_on_bad_params=>0" to the HTML::Template constructor to prevent the presence of the "err_" tokens from triggering an error when the errors are *not* being displayed. Data::FormValidator profile This can either be provided as a hash reference, or as the name of a CGI::Application method that will return such a hash reference. HTML::FillInForm options (optional) If desired, you can pass additional options to the HTML::FillInForm "fill" method through a hash reference. See an example above. Additionally, the value of the 'dfv_defaults' param from the calling object is optionally used to pass defaults to the "new()" constructor. $self->param('dfv_defaults') By setting this to a hash reference of defaults in your "cgiapp_init" routine in your own super-class, you could make it easy to share some default settings for Data::FormValidator across several forms. Of course, you could also set parameter through an instance script via the PARAMS key. Here's an example that I've used: sub cgiapp_init { my $self = shift; # Set some defaults for DFV unless they already exist. $self->param('dfv_defaults') || $self->param('dfv_defaults', { missing_optional_valid => 1, filters => 'trim', msgs => { any_errors => 'err__', prefix => 'err_', invalid => 'Invalid', missing => 'Missing', format => '%s', }, }); } Now all my applications that inherit from a super class with this "cgiapp_init()" routine and have these defaults, so I don't have to add them to every profile. validate_rm Works like "check_rm" above, but returns the old style $valid hash reference instead of the results object. EXAMPLE In a CGI::Application module: # 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_profile'); 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_', }, }; } In page.html: