I'm building a registration form for a little league, and it's really important that the date of birth field is entered correctly, otherwise you have 13 year olds playing T-Ball. I want the users to enter the date of birth twice, then validate that both entries match.
I managed to kludge together a custom validation that does this, but I don't like using the $_POST
global variables. Is there a better way to write this?
// Value of field 3_31 must match 3_6 and vice versa
add_filter("gform_field_validation_3_31", "custom_validation", 10, 4);
add_filter("gform_field_validation_3_6", "custom_validation", 10, 4);
function custom_validation($result, $value, $form, $field){
$submission1 = $_POST['input_6'];
$submission2 = $_POST['input_31'];
if($result["is_valid"] && ($submission1 != $submission2)){
$result["is_valid"] = false;
$result["message"] = "The date of birth fields don't match. Please make sure they are the same.";
}
return $result;
}