Leser: 12
QuoteValue for constraint_method 'test2' not a code reference or Regexp . Do you need func(), not 'func'? at /usr/lib/perl5/site_perl/5.8.8/Data/FormValidator.pm line 979.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/perl use strict; use warnings; use Data::FormValidator::Constraints qw(:closures); use Data::FormValidator; my %input = ( input1 => 'eins', input2 => 'zwei', input3 => 'drei', input4 => 'vier'); my $results = validate_input(\%input); print "result=$results\n"; sub validate_input{ my $input_hash_ref = shift; my $big_test = { filters => 'trim', required => [qw( input1 input2 input3 input4 )], constraint_methods => { test1 => validate_test1( 'exists', {fields => [qw( input1 ) ]} ), test2 => validate_test2( 'exists', {fields => [qw( input2 ) ]} ), test3 => validate_test3( 'exists', {fields => [qw( input3 ) ]} ), test4 => validate_test4( 'exists', {fields => [qw( input4 ) ]} ), } }; my $results = Data::FormValidator->check($input_hash_ref, $big_test); return($results); } sub validate_test1{ return; } sub validate_test2{ return; } sub validate_test3{ return; } sub validate_test4{ return; }
2009-03-17T10:58:43 SuperfrankCode (perl): (dl )1 2 3 4 5[...] test2 => validate_test2( 'exists', {fields => [qw( input2 ) ]} ), [...]
1 2 3 4 5 6 7 8 9 10
my $big_test = { filters => 'trim', required => [qw( input1 input2 input3 input4 )], constraint_methods => { test1 => validate_test1( 'exists', {fields => [qw( input1 ) ]} ), } };
print "blubb\n";
1 2 3 4 5 6
constraint_methods => { email => email(), prospective_date => coolness( 40, 60, {fields => [qw/personality smarts good_looks/]} ), }
1 2 3 4 5 6
constraint_methods => { email => validate_test2(), prospective_date => coolness( 40, 60, {fields => [qw/personality smarts good_looks/]} ), }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#!/usr/bin/perl use strict; use warnings; use Data::FormValidator::Constraints qw(:closures); use Data::FormValidator; my %input = ( input1 => 'eins', input2 => 'zwei', input3 => 'drei', input4 => 'vier'); my $results = validate_input(\%input); print "result=$results\n"; # Print the name of missing fields if ( $results->has_missing ) { for my $f ( $results->missing ) { print $f, " is missing\n"; } } # Print the name of invalid fields if ( $results->has_invalid ) { for my $f ( $results->invalid ) { print $f, " is invalid: ", $results->invalid( $f ), "\n"; my $array_ref = $results->invalid( $f ); my @array = @$array_ref; foreach(@array){ print $_ . ' array' . "\n"; } } } # Print unknown fields if ( $results->has_unknown ) { for my $f ( $results->unknown ) { print $f, " is unknown\n"; } } # Print valid fields for my $f ( $results->valid() ) { print 'valid ' . $f, " = ", $results->valid( $f ), "\n"; } sub validate_input{ my $input_hash_ref = shift; my $big_test = { filters => 'trim', required => [qw( input1 input2 input3 input4 )], constraint_methods => { input1 => validate_test1( 'exists', {fields => [qw( input1 ) ]} ), input2 => validate_test2( 'exists', {fields => [qw( input2 ) ]} ), input3 => validate_test3( 'exists', {fields => [qw( input3 ) ]} ), input4 => validate_test4( 'exists', {fields => [qw( input4 ) ]} ), } }; my $results = Data::FormValidator->check($input_hash_ref, $big_test); print "result1=$results\n"; return($results); } sub validate_test1{ my ($type,$attrs) = @_; return sub { my $dfv = shift; $dfv->name_this('validate_test1'); # value of 'prospective_date' parameter my $val = $dfv->get_current_constraint_value(); # get other data to refer to my $data = $dfv->get_filtered_data; return(undef); } } sub validate_test2{ my ($type,$attrs) = @_; return sub { my $dfv = shift; $dfv->name_this('validate_test2'); # value of 'prospective_date' parameter my $val = $dfv->get_current_constraint_value(); # get other data to refer to my $data = $dfv->get_filtered_data; return(1); } } sub validate_test3{ my ($type,$attrs) = @_; return sub { my $dfv = shift; $dfv->name_this('validate_test3'); # value of 'prospective_date' parameter my $val = $dfv->get_current_constraint_value(); # get other data to refer to my $data = $dfv->get_filtered_data; return(1); } } sub validate_test4{ my ($type,$attrs) = @_; return sub { my $dfv = shift; $dfv->name_this('validate_test4'); # value of 'prospective_date' parameter my $val = $dfv->get_current_constraint_value(); # get other data to refer to my $data = $dfv->get_filtered_data; return(1); } }
my $val = $dfv->get_current_constraint_value();