Hello again Maryana,

It appears that you are not following the format of the example given
below, 
which is the cause of you error. You have the right idea about how to
call an 
anonymous subroutine (like this: \&subroutine ). Here's a test script
with the
syntax you are looking for:
#######
use Data::FormValidator;
use strict;

my $input_profile = 
{
   optional => [ qw( my_field other_field) ],
   constraints => {
                  my_field => {
                                constraint => \&custom_constraint,
                                params     => [ qw( my_field other_field ) ],
                   } 
   }                
};

my $validator = new Data::FormValidator({default => $input_profile});

my $input_hashref = {   
        my_field => 'toast', 
    other_field => 'jam',
};

sub custom_constraint {
        my ($my_field, $other_fields) = @_;
        return  if ($my_field eq $other_fields);
        
}

my  ($valids, $missings, $invalids, $unknowns) = 
        $validator->validate($input_hashref, 'default');

use Data::Dumper; 
print "valid: ". Dumper ($valids);
print "missing: ". Dumper ($missings);
print "invalid: ". Dumper ($invalids);

####


Maryana Osipchuk wrote:
> 
> Hi, Mark!
> 
> Thanx for answer - it's partly help me to resolve my problem (now I use 
>Data::FormValidator). Tnx for so usefull module ;o)
> 
> But to call my function I need do it in that way:
> 
> p1 => {
>               constraint => \&main::valid_equiv,
>               params => [ qw (p1 p2)],
>       },
> when I try to call it (as described in docs, where cc_number name of builtin 
>validator)
> 
> p1 => {
>               constraint => "valid_equiv",
>               params => [ qw (p1 p2)],
>       },
> 
> I receive an error:
> Undefined subroutine &Data::FormValidator::valid_valid_equiv called at 
>C:/Perl/lib/Data/FormValidator.pm line 579.
> There are no samples in docs how to call external subroutine.
> 
> Tnx a lot for answer ;-)
> 
> --
> Maryana
> 
> ----- message  --------
> 
> > Hello Maryana,
> >
> > First, if you just learning HTML::FormValidator, I suggest looking into
> > Data::FormValidator. It contains all the old functions plus a few new features.
> >
> > In your case, I think your solution may be found an example in the
> > documentation which looks like this:
> >
> >     {
> >         customer_infos => {
> >              constraints => {
> >                 cc_no      => {  constraint  => "cc_number",
> >                                  params      => [ qw( cc_no cc_type ) ],
> >                                 },
> > }
> > }
> >
> >
> > # cc_no is the field name with the constraint
> > # cc_number is the custom function
> >
> >    -mark

-- 
 . . . . . . . . . . . . . . . . . . . . . . . . . .
   Mark Stosberg              Principal Developer  
   [EMAIL PROTECTED]       Summersault, LLC     
   v: 765-939-9301 ext 223    website development  
 . . . . . http://www.summersault.com/ . . . . . . .

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to