In a CGI::Application application, I am using CGI::Application::ValidateRM to validate form data. Today I have found a case where ValidateRM appears to fail the validation of a field. It is a time field, and is required in hh:mm:ss format, but if I enter say, 09, I get the following in the results object:
So I can see the Data::FormValidator seems to be doing its part. Now comes the fun. I am supposed to get an error page back, but I don't!'invalid' => { 'intstart' => [ 'date_and_time' ] }
Here is the runmode that is doing the validating:
And I get this as the output:sub pr_businesshours_process { my $self = shift; my $q = $self->query; my ($results, $err_page) = $self->check_rm('pr_businesshours_edit_ +display', { required => [qw/intervalid/], optional => [qw/intstart intend intint/], filters => ['trim'], validator_packages => [qw(Data::FormValidator::Constraints +::Dates)], constraints => { intstart => { name => 'date_and_time', constraint_method => 'date_and_time', params => [ \'hh:mm:ss' ], }, intend => { name => 'date_and_time', constraint_method => 'date_and_time', params => [ \'hh:mm:ss' ], }, }, msgs => { constraints => { 'date_and_time' => "Invalid time format", }, any_errors => 'err__', prefix => 'err_', }, } ); print STDERR Dumper $results; #print STDERR $err_page; return $err_page if $err_page; # do something with $results->valid here. my $output = $q->start_html; $output .= "<p>Page appears to have validated<br>Start: " . $q->pa +ram('intstart') . " End: " . $q->param('intend'); return $output; }
So you can see that the error page is not being generated.Page appears to have validated Start: 09 End: 00:00:00
To try and see what was happening I created a test, and would you know it, it worked perfectly (it is at http://posiedon.mine.nu/app/date_form_validation.cgi if you want to have a look. And the entire code, including the template can be found on jdtoronto's scratchpad. UPDATED: Code here also:
/* date_form_validation.cgi #!/usr/local/bin/perl use strict; use DateFormValidation; my $webapp = DateFormValidation->new(); $webapp->run(); /* DateFormValidation.pm #!/usr/local/bin/perl # package DateFormValidation; use base CGI::Application; use CGI::Application::ValidateRM; use Data::Dumper; use strict; sub setup { my $self = shift; $self->tmpl_path('/home/appsys/www/htdocs/templates/'); $self->start_mode('form_display'); $self->run_modes ( 'form_display' => \&form_display, 'mode_0114' => \&form_process, ); } sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('app03/pr_businesshours_edit_test.html', +die_on_bad_params => 0); $t->param($errs) if ref $errs; $t->param( intdow => 'Mon', inttype => 0, intstart => '00:00:00', intend => '00:00:00', intint => 30, dow => 0, providerid => 4, intervalid => 1, ); return $t->output; } sub form_process { my $self = shift; my $q = $self->query; my ($results, $err_page) = $self->check_rm('form_display', $self-> +_bh_profile ); print STDERR Dumper $results; #print STDERR $err_page; return $err_page if $err_page; # do something with $results->valid here. my $output = $q->start_html; $output .= "<p>Page appears to have validated<br>Start: " . $q->pa +ram('intstart') . " End: " . $q->param('intend'); return $output; } sub _bh_profile { return { required => [qw/intervalid/], optional => [qw/intstart intend intint/], filters => ['trim'], validator_packages => [qw(Data::FormValidator::Constraints::Da +tes)], constraints => { intstart => { name => 'date_and_time', constraint_method => 'date_and_time', params => [ \'hh:mm:ss' ], }, intend => { name => 'date_and_time', constraint_method => 'date_and_time', params => [ \'hh:mm:ss' ], }, }, msgs => { constraints => { 'date_and_time' => "Invalid time format", }, any_errors => 'err__', prefix => 'err_', }, }; } 1; /* The template <p>Provider ID: <tmpl_var provider_id></p> <div align="left"> <table border="0" cellpadding="2" cellspacing="2" width="436"> <tr> <td class="lbl">Day</td> <td class="lbl">Type</td> <td></td> <td></td> <td></td> <td></td> </tr> <form name="FormName" action="/app/date_form_validation.cgi" m +ethod="post"> <tr> <td class="value"><tmpl_var intdow></td> <td class="value"><tmpl_var inttype></td> <td class="lbl">Start</td> <td class="value"><input type="text" name="intstart" s +ize="10" value="<tmpl_var intstart>"></td> <td class="err"><tmpl_var err_intstart></td> </tr> <tr> <td></td> <td></td> <td class="lbl">End</td> <td class="value"><input type="text" name="intend" siz +e="10" value="<tmpl_var intend>"></td> <td class="err"><tmpl_var err_intend></td> </tr> <tr> <td></td> <td></td> <td class="lbl">Interval</td> <td class="value"><input type="text" name="intint" siz +e="10" value="<tmpl_var intint>"></td> <td class="err"><tmpl_var err_intint></td> <td><input type="submit" name="_save" value="Save"></t +d> <input type="hidden" value="<tmpl_var dow>" name="dow" +><input type="hidden" value="<tmpl_var providerid>" name="prov"><inpu +t type="hidden" value="<tmpl_var intervalid>" name="intervalid"><inpu +t type="hidden" value="mode_0114" name="rm"></tr> </tr> </form> </table> </div>
CGI::Application::ValidateRM is used extensively throughout the application and works just fine. This is the only place where I use the date/time constraints though.
If anybody has any clues they would be greatly apprecaited, or I am going to have to hack together something else to handle this until I can make it work.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |