Last active
August 29, 2015 14:01
-
-
Save mandiwise/666b6576fe5ffda86261 to your computer and use it in GitHub Desktop.
Checking to see if the field contained "Vancouver" and failing validation if it does.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_custom_validation( $validation_result ) { | |
$form = $validation_result["form"]; | |
// Sorry, you don't get to live in Vancouver... | |
if ( $_POST['input_1'] == 'Vancouver' ) { | |
$validation_result["is_valid"] = false; | |
foreach ( $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, you can't enter Vancouver here!"; | |
break; | |
} | |
} | |
} | |
// Assign modified $form object back to the validation result | |
$validation_result["form"] = $form; | |
return $validation_result; | |
} | |
add_filter( 'gform_validation_[your form ID]', 'my_custom_validation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment