soon_j has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks and gurus, I am in need of help in formatting the dependencies of my Data::FormValidator profile. My skill on using Perl is just average or below that and I easily get lost on confusing routines. I need your kind inputs.

Just an overview, I have the three fields described below in my form:

<select name="f_course"> <option value="Select Course">Select Course</option> <option value="Course A">Course A</option> <option value="Course B">Course B</option> </select> <select name="f_month"> <option value="Select Month">Select Month</option> <option value="1">January</option> <option value="2">February</option> ........ <option value="11">November</option> <option value="12">December</option> </select> <select name="f_year"> <option value="Select Year">Select Year</option> <option value="2009">2009</option> <option value="2008">2008</option> ........ <option value="2003">2003</option> <option value="2002">2002</option> </select>

The above 3 fields are actually optional fields. However, if either of the 3 fields is filled up, the remaining 2 fields would be required also. Example: if the user selects "Course A" from the f_course field, then he must also select the proper f_month and f_year, otherwise an error will be returned prompting the user to complete these 3 fields.

The first option on each of the 3 fields is something like "Select Course" or "Select Month" or "Select Year". If this is the returned value for the corresponding field, this will be treated similar to an empty field (thereby requiring the user to make a valid selection... if in case one of the 3 fields is filled up).

I am hoping you can help me do the above routine that can be incorporated as a dependency...
my $profile = { optional => [qw( f_course f_month f_year )], required => [qw( f_a, f_b )], dependencies => { # If f_course is entered, make f_month and f_year required # Or if f_month is entered, make f_course and f_year required # Or if f_year is entered, make f_course and f_month required }, };

... where I need only to monitor the returned $obj->has_missing.

Thanks everyone for even taking the time to read this. Your inputs will be very much appreciated.

Replies are listed 'Best First'.
Re: Need Help on Dependencies using Data::FormValidator
by 1Nf3 (Pilgrim) on Jul 15, 2009 at 05:58 UTC

    I'll try to help, but my knowledge is limited to the documentation of the module (Data::FormValidator). It seems that dependency groups are just what you need:

    dependency_groups => { # if either field is filled in, they all become required course_group => [qw/f_course f_month f_year/], }

    Regards,
    Luke