php - Conditional Logic Form Validation -
i'm having issues writing logic script. can't seem wrap head around it.
i have form contains 6 quantity fields, , 2 corresponding check boxes each quantity field.
quantity fields referenced in variables $q1, $q2, $q3, $q4, $q5, $q6
. check boxes referenced in variables $c1_1, $c1_2, $c2_1, $c2_2
... etc.
the logic want achieve is, if input number quantity field, either 1 of 2 corresponding checkboxes must checked or form invalidates.
my current code looks this:
if( ($q1 !== "" && ($c1_1 == "" || $c1_2 == "")) || ($q2 !== "" && ($c2_1 == "" || $c2_2 == "")) || ($q3 !== "" && ($c3_1 == "" || $c3_2 == "")) || ($q4 !== "" && ($c4_1 == "" || $c4_2 == "")) || ($q5 !== "" && ($c5_1 == "" || $c5_2 == "")) || ($q6 !== "" && ($c6_1 == "" || $c6_2 == "")) ) { $is_valid = false; } else { $is_valid = true; }
what's wrong code when go test script, requires both checkboxes checked validate.
if understood correctly, want invalidate if meet 1 of this:
- a field empty
- both checkboxes (belonging field) unchecked
so be
if( ($q1 !== "" && ($c1_1 == "" && $c1_2 == "")) || ($q2 !== "" && ($c2_1 == "" && $c2_2 == "")) || ($q3 !== "" && ($c3_1 == "" && $c3_2 == "")) || ($q4 !== "" && ($c4_1 == "" && $c4_2 == "")) || ($q5 !== "" && ($c5_1 == "" && $c5_2 == "")) || ($q6 !== "" && ($c6_1 == "" && $c6_2 == "")) ) { $is_valid = false; } else { $is_valid = true; }
with or without inner ().
haven't tried myself, should work.
Comments
Post a Comment