in reply to Data::FormValidator constraints against local sub routine

I meant to send this comment earlier in the day, I hope it is still useful:
FRAGMENT - not complete: my ($results, $err_page) = $self->check_rm('qs_display', { required => [qw/upfirstname uplastname upemail upusername +uppassword confirm_password/], optional => [qw/upzip upcountry/], filters => ['trim'], constraints => { uppassword => { #Make sure passwords are the same name => 'user_passwords', constraint => \&check_password, params => [qw(uppassword confirm_password)], }, upusername => { #Is username unique? name => 'user_username', constraint => \&check_username, params => [qw(upusername)], }, upemail => 'email', upzip => 'zip_or_postcode', }, msgs => { any_errors => 'err__', prefix => 'err_', constraints => { 'user_passwords' => "Your passwords don't match", 'user_username' => "Username not unique", }, }, } ); return $err_page if $err_page; # Results are valid my $dfv_results = $results->valid(); print STDERR Dumper( $dfv_results ); $self->header_type('redirect'); $self->header_props( -url => 'http://posiedon.mine.nu'); return; } sub check_password { my ($p1, $p2) = @_; if ($p1 eq $p2) { return 1; } else { return 0; } }
I think it is pretty straightforward. I get the two passowrd values from my form, the trivial sub (which could be much simplified!) merely returns true or false. I am using D::FV 3.14 with CGI::Application

The code is not original, Cees Hek gave me the outline in an answer to a question on the CGI::App mail list.

jdtoronto