Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Data::FormValidator inverse dependencies?

by meraxes (Friar)
on Nov 10, 2005 at 21:48 UTC ( #507565=perlquestion: print w/ replies, xml ) Need Help??
meraxes has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks-of-unusual-size,

I've got a bit of a situtation with Data::FormValidator and a form... not sure what to do.

The form contains a checkbox called same_as_billing. If same_as_billing is checked that means re-use the billing address as the shipping address. Otherwise, I have to get shipping address information. That means I want Data::FormValidator to make some other fields required. Essentially, I want the inverse of the dependencies clause (since undef is not a valid hash key). So I know I can't do something like this:

dependencies => { 'same_as_billing' => { undef => [ qw/street1 street2 city/ ] }, }

I realize I could flip the meaning of the checkbox to be different_from_billing and I could easily do something like this:

dependencies => { different_from_billing => [ qw/street1 street2 city/ ], }

... but Marketing dislikes the wording. Yay.

Manually tinkering with the POST/GET var before using Data::FormValidator is one way I could get around this by getting the inverse value but that seems messy and could confuse someone just looking at the code. Is there a way I can do this purely using DFV?

Many thanks,
meraxes

Comment on Data::FormValidator inverse dependencies?
Select or Download Code
Re: Data::FormValidator inverse dependencies?
by philcrow (Priest) on Nov 10, 2005 at 22:08 UTC
    Could you switch to constraint_methods for the billing fields? I haven't done this, so I'm not going to give an example. But look in the perldoc for Data::FormValidator in the section called VALIDATING INPUT BASED ON MULTIPLE FIELDS. It refers to the perldoc for Data::FormValidator::Constraints and its section WRITING YOUR OWN VALIDATION ROUTINES.

    I think those sections and a bit of play will work.

    Essentially, you write your own validation routines for your billing address fields. Each of those routines can resceive the value of the checkbox as a parameter.

    Phil

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://507565]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-12-28 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls