Maybe I am cognitively challenged, but I thought I did what the documentation says to do if there are multiple constraints to apply to a given field. To be clear, here is what the documentation says (a direct quote, but I don't see anything in the interface for editing this that lets me distinguish between such a quote and what I write)
MULTIPLE CONSTRAINTS
Multiple constraints can be applied to a single field by defining the value of the constraint to be an array reference. Each of the values in this array can be any of the constraint types defined above.
When using multiple constraints it is important to return the name of the constraint that failed so you can distinguish between them. To do that, either use a named constraint, or use the hash ref method of defining a constraint and include a name key with a value set to the name of your constraint. Here's an example:
my_zipcode_field => [ 'zip', { constraint => '/^406/', name => 'starts_with_406', } ],
You can use an array reference with a single constraint in it if you just want to have the name of your failed constraint returned in the above fashion. Read about the validate() function above to see how multiple constraints are returned differently with that method.
Now here is what I tried:
ccexpiry => [ 'ccexp', { constraint => sub { my ($dfv,$val) = @_; return $val =~ m/^\d{4}$/, }, name => 'must be_4_digits' }, { constraint => after_today('%m%y'), name => 'card_expired' } ],
Of course, this is part of a large profile hash that, prior to my attempt to use multiple constraints, was working fine. Now, here is the error I get:
[Thu Jan 31 15:58:27 2013] [error] [client 127.0.0.1] Value for constraint_method 'ccexp' not a code reference or Regexp . Do you need func(), not 'func'? at C:/Perl64/site/lib/Data/FormValidator.pm line 974., referer: http://localhost:9080/test.dfv.htmlI am using the following packages.
use Business::CreditCard; use Business::CCCheck; use Data::FormValidator; use Data::FormValidator::Constraints qw(:closures); use Data::FormValidator::Constraints::DateTime qw(:all);
If there are others that you believe would be useful, I'd appreciate hearing about them, but as far as I can see, the ones I am using are pretty much sufficient for what I need right now.
Any insight on how I can fix these constraints would be appreciated.
Thanks
Ted
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |