|
NAMECGI::Application::Plugin::ValidateRM - Help validate CGI::Application run modes using Data::FormValidatorSYNOPSISuse CGI::Application::Plugin::ValidateRM; my $results = $self->check_rm('form_display','_form_profile') || return $self->check_rm_error_page; # Optionally, you can pass additional options to HTML::FillInForm->fill() my $results = $self->check_rm('form_display','_form_profile', { fill_password => 0 }) || return $self->check_rm_error_page; DESCRIPTIONCGI::Application::Plugin::ValidateRM helps to validate web forms when using the CGI::Application framework and the Data::FormValidator module.check_rm()Validates a form displayed in a run mode with a "Data::FormValidator" profile, returning the results and possibly an a version of the form page with errors marked on the page.In scalar context, it returns simply the Data::FormValidator::Results object which conveniently evaluates to false in a boolean context if there were any missing or invalide fields. This is the recommended calling convention. In list context, it returns the results object followed by the error page, if any. This was the previous recommended syntax, and was used like this: my ($results,$err_page) = $self->check_rm('form_display','_form_profile'); return $err_page if $err_page; The inputs are as follows:
Additional Options To control things even more, you can set parameters in your CGI::Application object itself.
CGI::Application::Plugin::Forward supportExperimental support has been added for CGI::Application::Plugin::Forward, which keeps the current run mode up to date. This would be useful if you were automatically generating a template name based on the run mode name, and you wanted this to work with the form run mode used with ::ValidateRM.If we detect that ::Forward is loaded, we will set the current run mode name to be accurate while the error page is being generated, and then set it back to the previous value afterwards. There is a caveat: This currently only works when the run name name is the same as the subroutine name for the form page. If they differ, the current run mode name inside of the form page will be inaccurate. If this is a problem for you, get in touch to discuss a solution. check_rm_error_page()After check_rm() is called this accessor method can be used to retrieve the error page described in the check_rm() docs above. The method has an alias named "dfv_error_page()" if you find that more intuitive.dfv_results()$self->dfv_results; After "check_rm()" or "validate_rm()" has been called, the DFV results object can also be accessed through this method. I expect this to be most useful to other plugin authors. validate_rm()Works like "check_rm" above, but returns the old style $valid hash reference instead of the results object. It's no longer recommended, but still supported.EXAMPLEIn 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: <!-- tmpl_if some_errors --> <h3>Some fields below are missing or invalid</h3> <!-- /tmpl_if --> <form> <input type="text" name="email"> <!-- tmpl_var err_email --> </form> SEE ALSOCGI::Application, Data::FormValidator, HTML::FillInForm, perl(1)AUTHORMark Stosberg <mark@summersault.com>MAILING LISTIf you have any questions, comments, bug reports or feature suggestions, post them to the support mailing list! This the Data::FormValidator list. To join the mailing list, visit <http://lists.sourceforge.net/lists/listinfo/cascade-dataform>LICENSECopyright (C) 2003-2005 Mark Stosberg <mark@summersault.com>This module is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. For a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Visit the GSP FreeBSD Man Page Interface. |