I am trying to use the gform_validation hook to check against an array of codes that we will be sending out to customers. I need to form to only accept the codes that we are using.
I was hoping it was as simple as using the gform_validation to check against an array like so:
add_filter('gform_validation', 'custom_validation');
function custom_validation($validation_result){
//supposing we don't want input 1 to be a value of 86
$code = array('aaa2', 'aaa3', 'aaa4');
if($_POST['input_1'] == $code){
// set the form validation to false
$validation_result["is_valid"] = false;
//finding Field with ID of 1 and marking it as failed validation
foreach($validation_result["form"]["fields"] as &$field){
//NOTE: replace 1 with the field you would like to validate
if($field["id"] == "1"){
$field["failed_validation"] = true;
$field["validation_message"] = "Sorry, try again!";
break;
}
}
}
return $validation_result;
}
Ideally I would love to be able to check a table within our database, but I am not quite sure how that would be handled. Any help would be appreciated