[cgiapp] Data.FormValidator.js - New C::A validation plugin
Lyle
webmaster at cosmicperl.com
Wed Jan 28 21:40:15 EST 2009
Lyle wrote:
> Lyle wrote:
>> Joshua Miller wrote:
>>>> Joshua,
>>>> Have you managed to figure out a work around for:-
>>>>
>>>> 'constraints' => {
>>>> 'password1' => {
>>>> 'constraint' => "check_passwords",
>>>> 'params' => [ qw( password1 password2 ) ],
>>>> },
>>>> },
>>>> ...
>>>> sub check_passwords {
>>>> my ( $pw1, $pw2 ) = @_;
>>>> if ( $pw1 eq $pw2 ) {
>>>> return 1;
>>>> } else {
>>>> return 0;
>>>> }
>>>> }
>
> I've just tried this code in DFV and I can't get it working? I'm
> getting the error
> "No constraint found named 'must_match' at
> Data/FormValidator/Results.pm line 965."
>
> Can't seem to figure out what I'm missing...
>
> Should be working according to the guide I followed at:-
> http://search.cpan.org/~purdy/Data-FormValidator-Tutorial-1.61/lib/Data/FormValidator/Tutorial.pm
>
Just read
http://search.cpan.org/~markstos/Data-FormValidator-4.63/lib/Data/FormValidator/Constraints.pm#Old_School_Constraints
Seems the example from that tutorial shows a very old way of doing it
(it's been replaced twice!)
Also I kept getting that error until I made it a sub routine reference.
What I got working:-
'constraints' => {
'password1' => {
'constraint_method' => \&must_match,
'params' => [ qw( password1 password2 ) ],
},
},
...
sub must_match {
my ( $dfv, $val1, $val2) = @_;
$dfv->name_this('match');
if ( $val1 eq $val2 ) {
return 1;
}#if
else {
return 0;
}#else
}#sub
Lyle
More information about the cgiapp
mailing list