I have a form which asks whether a registrant is requesting vegetarian meal(s). If the answer is yes, then 3 number fields appear asking how many meals for adults, older children, and younger children. If the registrant checks "yes" to request vegetarian meals but then doesn't modify any of the 3 number fields, I want the form to prompt the registrant to choose a non-zero number in at least 1 of those 3 number fields. So I've created a number field (id 39) in the form (id 12) which totals the 3 number fields, and added the following code to functions.php
add_filter("gform_field_validation_12_39", "custom_validation", 10, 4);
function custom_validation($result, $value, $form, $field){
if($result["is_valid"] && intval($value) == 0){
$result["is_valid"] = false;
$result["message"] = "Total vegetarian meals must be greater than zero";
}
return $result;
}
But it doesn't generate an error message if I leave all the 3 number fields as zero. What am I missing?