Re: [dfv] Multiple constraint_methods for a field
Status: Inactive
Brought to you by:
markjugg
From: Jonas B. N. <jo...@gm...> - 2016-07-11 07:57:18
|
Hi Dave. Not the prettiest solution. but you could do a two phase validation: my $dfv = Data::FormValidator->new({ profile_1 => { # usual profile definition here }, profile_2 => { # another profile definition }, }); my $results1 = $dfv->check(\%input_hash,'profile_1’); my $results2 = $dfv->check(\%input_hash,'profile_2'); Examples lifted from the documentation: https://metacpan.org/pod/Data::FormValidator jonasbn > On 11 Jul 2016, at 01:44, David Williamson <dav...@va...> wrote: > > I have a form field "email". I want to apply two constraints to it. > Firstly, I want to check that the email entered looks valid. Secondly, > if (and only if) the email entered looks valid I want to check that is > known to be associated with a society. That second check is specific to > the particular functionality of my web site. > > Here is my entry for the email field in constraint_methods. > > email => [ > { > constraint_method => email , > name => 'email_valid' > } , > { > constraint_method => representative_known , > fields => [ qw / society / ] > } , > ] , > > I've used the email constraint from Data::FormValidator::Constraints and > provided my own name to associate to my own error message. I have > another error message associated with the representative_known constraint. > > When I test with an invalid email address I get both error messages > returned in an array, which suggests to me that both constraints have > been executed. How do I stop the representative_known constraint from > being run if the email fails the email constraint? > > Dave > > > ------------------------------------------------------------------------------ > Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San > Francisco, CA to explore cutting-edge tech and listen to tech luminaries > present their vision of the future. This family event has something for > everyone, including kids. Get more information and register today. > http://sdm.link/attshape > _______________________________________________ > Cascade-DataForm mailing list > Cas...@li... > https://lists.sourceforge.net/lists/listinfo/cascade-dataform |