.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::ValidateRM 3pm" .TH CGI::Application::Plugin::ValidateRM 3pm "2021-01-05" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::ValidateRM \- Help validate CGI::Application run modes using Data::FormValidator .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use CGI::Application::Plugin::ValidateRM; \& \& my $results = $self\->check_rm(\*(Aqform_display\*(Aq,\*(Aq_form_profile\*(Aq) || return $self\->check_rm_error_page; \& \& \& # Optionally, you can pass additional options to HTML::FillInForm\->fill() \& my $results = $self\->check_rm(\*(Aqform_display\*(Aq,\*(Aq_form_profile\*(Aq, { fill_password => 0 }) \& || return $self\->check_rm_error_page; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" CGI::Application::Plugin::ValidateRM helps to validate web forms when using the CGI::Application framework and the Data::FormValidator module. .SS "\fBcheck_rm()\fP" .IX Subsection "check_rm()" Validates a form displayed in a run mode with a \f(CW\*(C`Data::FormValidator\*(C'\fR profile, returning the results and possibly an a version of the form page with errors marked on the page. .PP 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. .PP 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: .PP .Vb 2 \& my ($results,$err_page) = $self\->check_rm(\*(Aqform_display\*(Aq,\*(Aq_form_profile\*(Aq); \& return $err_page if $err_page; .Ve .PP The inputs are as follows: .IP "Return run mode" 4 .IX Item "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. .Sp The errors will be passed in as a hash reference, which can then be handed to a templating system for display. Following the above example, the \fBform_display()\fR routine might look like: .Sp .Vb 6 \& sub form_display { \& my $self = shift; \& my $errs = shift; # <\-\- prepared for form reloading \& my $t = $self\->load_tmpl(\*(Aqform_display.html\*(Aq); \& $t\->param($errs) if $errs; # <\-\- Also necessary. \& # ... \& \& } .Ve .Sp The fields should be prepared using Data::FormValidator's built-in support for returning error messages as a hash reference. See the documentation for \f(CW\*(C`msgs\*(C'\fR in the Data::FormValidator::Results documentation. .Sp Returning the errors with a prefix, such as \*(L"err_\*(R" is recommended. Using \&\f(CW\*(C`any_errors\*(C'\fR is also recommended to make it easy to display a general \*(L"we have some errors\*(R" message. .Sp HTML::Template users may want to pass \f(CW\*(C`die_on_bad_params=>0\*(C'\fR to the HTML::Template constructor to prevent the presence of the \*(L"err_\*(R" tokens from triggering an error when the errors are \fInot\fR being displayed. .IP "Data::FormValidator profile" 4 .IX Item "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. .IP "HTML::FillInForm options (optional)" 4 .IX Item "HTML::FillInForm options (optional)" If desired, you can pass additional options to the HTML::FillInForm \&\fBfill()\fR method through a hash reference. See an example above. .PP \fIAdditional Options\fR .IX Subsection "Additional Options" .PP To control things even more, you can set parameters in your CGI::Application object itself. .IP "dfv_defaults" 4 .IX Item "dfv_defaults" The value of the 'dfv_defaults' param is optionally used to pass defaults to the Data::FormValidator \fBnew()\fR constructor. .Sp .Vb 1 \& $self\->param(dfv_defaults => { filters => [\*(Aqtrim\*(Aq] }) .Ve .Sp By setting this to a hash reference of defaults in your \f(CW\*(C`cgiapp_init\*(C'\fR 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 \s-1PARAMS\s0 key. .Sp Here's an example that I've used: .Sp .Vb 2 \& sub cgiapp_init { \& my $self = shift; \& \& # Set some defaults for DFV unless they already exist. \& $self\->param(\*(Aqdfv_defaults\*(Aq) || \& $self\->param(\*(Aqdfv_defaults\*(Aq, { \& missing_optional_valid => 1, \& filters => \*(Aqtrim\*(Aq, \& msgs => { \& any_errors => \*(Aqerr_\|_\*(Aq, \& prefix => \*(Aqerr_\*(Aq, \& invalid => \*(AqInvalid\*(Aq, \& missing => \*(AqMissing\*(Aq, \& format => \*(Aq%s\*(Aq, \& }, \& }); \& } .Ve .Sp Now all my applications that inherit from a super class with this \&\f(CW\*(C`cgiapp_init()\*(C'\fR routine and have these defaults, so I don't have to add them to every profile. .IP "dfv_fif_class" 4 .IX Item "dfv_fif_class" By default this plugin uses HTML::FillInForm to fill in the forms on the error pages with the given values. This option let's you change that so it uses an HTML::FillInForm compatible class (like a subclass) to do the same work. .Sp .Vb 1 \& $self\->param(dfv_fif_class => \*(AqHTML::FillInForm::SuperDuper\*(Aq); .Ve .IP "dfv_fif_defaults" 4 .IX Item "dfv_fif_defaults" The value of the 'dfv_fif_defaults' param is optionally used to pass defaults to the HTML::FillInForm \f(CW\*(C`fill()\*(C'\fR method. .Sp .Vb 1 \& $self\->param(dfv_fif_defaults => {ignore_fields => [\*(Aqrm\*(Aq]}) .Ve .Sp By setting this to a hash reference of defaults in your \f(CW\*(C`cgiapp_init\*(C'\fR routine in your own super-class, you could make it easy to share some default settings for HTML::FillInForm across several forms. Of course, you could also set parameter through an instance script via the \s-1PARAMS\s0 key. .SS "CGI::Application::Plugin::Forward support" .IX Subsection "CGI::Application::Plugin::Forward support" Experimental 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. .PP 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. .SS "\fBcheck_rm_error_page()\fP" .IX Subsection "check_rm_error_page()" After \fBcheck_rm()\fR is called this accessor method can be used to retrieve the error page described in the \fBcheck_rm()\fR docs above. The method has an alias named \f(CW\*(C`dfv_error_page()\*(C'\fR if you find that more intuitive. .SS "\fBdfv_results()\fP" .IX Subsection "dfv_results()" .Vb 1 \& $self\->dfv_results; .Ve .PP After \f(CW\*(C`check_rm()\*(C'\fR or \f(CW\*(C`validate_rm()\*(C'\fR has been called, the \s-1DFV\s0 results object can also be accessed through this method. I expect this to be most useful to other plugin authors. .SS "\fBvalidate_rm()\fP" .IX Subsection "validate_rm()" Works like \f(CW\*(C`check_rm\*(C'\fR above, but returns the old style \f(CW$valid\fR hash reference instead of the results object. It's no longer recommended, but still supported. .SH "EXAMPLE" .IX Header "EXAMPLE" In a CGI::Application module: .PP .Vb 5 \& # 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(\*(Aqpage.html\*(Aq); \& \& $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(\*(Aqform_display\*(Aq,\*(Aq_form_profile\*(Aq); \& return $err_page if $err_page; \& \& #.. do something with DFV $results object now \& \& my $t = $self\->load_tmpl(\*(Aqsuccess.html\*(Aq); \& return $t\->output; \& \& } \& \& sub _form_profile { \& return { \& required => \*(Aqemail\*(Aq, \& msgs => { \& any_errors => \*(Aqsome_errors\*(Aq, \& prefix => \*(Aqerr_\*(Aq, \& }, \& }; \& } .Ve .PP In page.html: .PP .Vb 6 \& \&

Some fields below are missing or invalid

\& \&
\& \&
.Ve .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application, Data::FormValidator, HTML::FillInForm, \fBperl\fR\|(1) .SH "AUTHOR" .IX Header "AUTHOR" Mark Stosberg .SH "MAILING LIST" .IX Header "MAILING LIST" If 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 .SH "LICENSE" .IX Header "LICENSE" Copyright (C) 2003\-2005 Mark Stosberg .PP This module is free software; you can redistribute it and/or modify it under the terms of either: .PP a) the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, .PP or .PP b) the \*(L"Artistic License\*(R" .PP This program is distributed in the hope that it will be useful, but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See either the \s-1GNU\s0 General Public License or the Artistic License for more details. .PP For a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, \s-1MA 02111\-1307 USA\s0