Last active
October 12, 2020 22:03
-
-
Save rochow/643b6fdd0623fb8c5e3f to your computer and use it in GitHub Desktop.
Gravity Forms - Validation (Default Value = Fail)
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
<?php | |
// Gravity Forms Validation. Rejects any required input where $_POST value = default input value (ya, placeholders didn't use to exist!) | |
add_filter( 'gform_validation', 'mr_custom_validation' ); | |
function mr_custom_validation( $validation_result ){ | |
$form = $validation_result['form']; | |
foreach( $form['fields'] as &$field ){ | |
if( '1' == $field['isRequired'] && 'checkbox' != $field['type'] ) { | |
if( $field['defaultValue'] == $_POST[ 'input_' . $field['id'] ] ) { | |
$validation_result['is_valid'] = false; | |
$field['failed_validation'] = true; | |
$field['validation_message'] = "This field is invalid!"; | |
} | |
} | |
} | |
$validation_result['form'] = $form; | |
return $validation_result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment