Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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,

Replies are listed 'Best First'.
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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://507565]
Approved by Tanktalus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-24 13:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.