Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm using Data::FormValidator, which has saved me many lines of code and has greatly simplified my validation logic. Excellent module.

However, due my lack of Perl experience, I'm having trouble creating a D::FV profile to apply multiple constraints to a single query parameter. I've searched the POD, perlmonks and googled but didn't find anything that helped me see how to do it. Here is a snippet of what I've got so far:

my $ca_obj = shift; # CGI::Application object my $q = $ca_obj->query(); my $dfv_profile = { required => [qw (userid)], constraints => { userid => { name => 'userid_exists', constraint => sub { return !MyDBITools->user_exists($ca_obj); }, }, userid => { name => 'userid_untaint', constraint => qr/^[-\@\w.]+$/, }, }, msgs => { format => '%s', constraints => { 'userid_exists' => "User ID already exists.", 'userid_untaint'=> "User ID contains bad stuff", }, }, }; my $results = Data::FormValidator->check($q, $dfv_profile);

Using the code above, as I fully expected it to, the userid_untaint constraint is overriding the userid_exists constraint, because the second instance of the userid hash key is trashing the first. This is clear from my results. I get the "User ID contains bad stuff" error and the already existing user gets registered. If I remove the userid_untaint constraint, I get the expected error message "User ID already exists."

Does anyone know the proper syntax to write multiple constraints for a single variable?

Thanks,

Anne


In reply to Mulitple constraints for Data::FormValidator by Anneq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found