1CGI::Application::PlugiUns:e:rVaCloindtartiebRuMt(e3d)PCeGrIl::DAopcpulmiecnattaitoino:n:Plugin::ValidateRM(3)
2
3
4

NAME

6       CGI::Application::Plugin::ValidateRM - Help validate CGI::Application
7       run modes using Data::FormValidator
8

SYNOPSIS

10        use CGI::Application::Plugin::ValidateRM;
11
12        my  $results = $self->check_rm('form_display','_form_profile') || return $self->check_rm_error_page;
13
14
15        # Optionally, you can pass additional options to HTML::FillInForm->fill()
16        my $results = $self->check_rm('form_display','_form_profile', { fill_password => 0 })
17               || return $self->check_rm_error_page;
18

DESCRIPTION

20       CGI::Application::Plugin::ValidateRM helps to validate web forms when
21       using the CGI::Application framework and the Data::FormValidator
22       module.
23
24   check_rm()
25       Validates a form displayed in a run mode with a "Data::FormValidator"
26       profile, returning the results and possibly an a version of the form
27       page with errors marked on the page.
28
29       In scalar context, it returns simply the Data::FormValidator::Results
30       object which conveniently evaluates to false in a boolean context if
31       there were any missing or invalide fields. This is the recommended
32       calling convention.
33
34       In list context, it returns the results object followed by the error
35       page, if any.  This was the previous recommended syntax, and was used
36       like this:
37
38        my ($results,$err_page) = $self->check_rm('form_display','_form_profile');
39        return $err_page if $err_page;
40
41       The inputs are as follows:
42
43       Return run mode
44           This run mode will be used to generate an error page, with the form
45           re-filled (using HTML::FillInForm) and error messages in the form.
46           This page will be returned as a second output parameter.
47
48           The errors will be passed in as a hash reference, which can then be
49           handed to a templating system for display. Following the above
50           example, the form_display() routine might look like:
51
52            sub form_display {
53               my $self = shift;
54               my $errs = shift;                             # <-- prepared for form reloading
55               my $t = $self->load_tmpl('form_display.html');
56               $t->param($errs) if $errs;                    # <-- Also necessary.
57               # ...
58
59            }
60
61           The fields should be prepared using Data::FormValidator's built-in
62           support for returning error messages as a hash reference.  See the
63           documentation for "msgs" in the Data::FormValidator::Results
64           documentation.
65
66           Returning the errors with a prefix, such as "err_" is recommended.
67           Using "any_errors" is also recommended to make it easy to display a
68           general "we have some errors" message.
69
70           HTML::Template users may want to pass "die_on_bad_params=>0" to the
71           HTML::Template constructor to prevent the presence of the "err_"
72           tokens from triggering an error when the errors are not being
73           displayed.
74
75       Data::FormValidator profile
76           This can either be provided as a hash reference, or as the name of
77           a CGI::Application method that will return such a hash reference.
78
79       HTML::FillInForm options (optional)
80           If desired, you can pass additional options to the HTML::FillInForm
81           "fill" method through a hash reference. See an example above.
82
83       Additionally, the value of the 'dfv_defaults' param from the calling
84       object is optionally used to pass defaults to the "new()" constructor.
85
86         $self->param('dfv_defaults')
87
88       By setting this to a hash reference of defaults in your "cgiapp_init"
89       routine in your own super-class, you could make it easy to share some
90       default settings for Data::FormValidator across several forms. Of
91       course, you could also set parameter through an instance script via the
92       PARAMS key.
93
94       Here's an example that I've used:
95
96        sub cgiapp_init {
97            my $self = shift;
98
99            # Set some defaults for DFV unless they already exist.
100            $self->param('dfv_defaults') ||
101                $self->param('dfv_defaults', {
102                        missing_optional_valid => 1,
103                        filters => 'trim',
104                        msgs => {
105                            any_errors => 'err__',
106                            prefix     => 'err_',
107                            invalid    => 'Invalid',
108                            missing    => 'Missing',
109                            format => '<span class="dfv-errors">%s</span>',
110                        },
111                    });
112        }
113
114       Now all my applications that inherit from a super class with this
115       "cgiapp_init()" routine and have these defaults, so I don't have to add
116       them to every profile.
117
118   CGI::Application::Plugin::Forward support
119       Experimental support has been added for
120       CGI::Application::Plugin::Forward, which keeps the current run mode up
121       to date. This would be useful if you were automatically generating a
122       template name based on the run mode name, and you wanted this to work
123       with the form run mode used with ::ValidateRM.
124
125       If we detect that ::Forward is loaded, we will set the current run mode
126       name to be accurate while the error page is being generated, and then
127       set it back to the previous value afterwards. There is a caveat: This
128       currently only works when the run name name is the same as the
129       subroutine name for the form page.  If they differ, the current run
130       mode name inside of the form page will be inaccurate. If this is a
131       problem for you, get in touch to discuss a solution.
132
133   check_rm_error_page()
134       After check_rm() is called this accessor method can be used to retrieve
135       the error page described in the check_rm() docs above. The method has
136       an alias named "dfv_error_page()" if you find that more intuitive.
137
138   dfv_results()
139        $self->dfv_results;
140
141       After "check_rm()" or "validate_rm()" has been called, the DFV results
142       object can also be accessed through this method. I expect this to be
143       most useful to other plugin authors.
144
145   validate_rm()
146       Works like "check_rm" above, but returns the old style $valid hash
147       reference instead of the results object. It's no longer recommended,
148       but still supported.
149

EXAMPLE

151       In a CGI::Application module:
152
153        # This is the run mode that will be validated. Notice that it accepts
154        # some errors to be passed in, and on to the template system.
155        sub form_display {
156               my $self = shift;
157               my $errs = shift;
158
159               my $t = $self->load_tmpl('page.html');
160
161               $t->param($errs) if $errs;
162               return $t->output;
163        }
164
165        sub form_process {
166               my $self = shift;
167
168               use CGI::Application::Plugin::ValidateRM (qw/check_rm/);
169               my ($results, $err_page) = $self->check_rm('form_display','_form_profile');
170               return $err_page if $err_page;
171
172               #..  do something with DFV $results object now
173
174               my $t = $self->load_tmpl('success.html');
175               return $t->output;
176
177        }
178
179        sub _form_profile {
180               return {
181                       required => 'email',
182                       msgs => {
183                               any_errors => 'some_errors',
184                               prefix => 'err_',
185                       },
186               };
187        }
188
189       In page.html:
190
191        <!-- tmpl_if some_errors -->
192               <h3>Some fields below are missing or invalid</h3>
193        <!-- /tmpl_if -->
194        <form>
195               <input type="text" name="email"> <!-- tmpl_var err_email -->
196        </form>
197

SEE ALSO

199       CGI::Application, Data::FormValidator, HTML::FillInForm, perl(1)
200

AUTHOR

202       Mark Stosberg <mark@summersault.com>
203

MAILING LIST

205       If you have any questions, comments, bug reports or feature
206       suggestions, post them to the support mailing list! This the
207       Data::FormValidator list.  To join the mailing list, visit
208       http://lists.sourceforge.net/lists/listinfo/cascade-dataform
209       <http://lists.sourceforge.net/lists/listinfo/cascade-dataform>
210

LICENSE

212       Copyright (C) 2003-2005 Mark Stosberg <mark@summersault.com>
213
214       This module is free software; you can redistribute it and/or modify it
215       under the terms of either:
216
217       a) the GNU General Public License as published by the Free Software
218       Foundation; either version 1, or (at your option) any later version,
219
220       or
221
222       b) the "Artistic License"
223
224       This program is distributed in the hope that it will be useful, but
225       WITHOUT ANY WARRANTY; without even the implied warranty of
226       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either the
227       GNU General Public License or the Artistic License for more details.
228
229       For a copy of the GNU General Public License along with this program;
230       if not, write to the Free Software Foundation, Inc., 59 Temple Place,
231       Suite 330, Boston, MA 02111-1307 USA
232
233
234
235perl v5.12.0                      2010-0C4G-I3:0:Application::Plugin::ValidateRM(3)
Impressum