Created
April 29, 2022 17:21
Star
You must be signed in to star a gist
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
@link https: //gist.github.com/anythinggraphic/c5d9da935697df703ddd79883b1865f1 | |
/** | |
* Gravity Forms: Form Validation. | |
* | |
* The below looks for the words 'http' and 'https' upon after the user tries to submit the form. | |
* During form validation, if the words appear within the form, the form will not submit. | |
* The user will then be presented with a custom, informative, and actionable message. | |
* | |
* @author Anything Graphic | |
* @link https://anythinggraphic.net | |
* @link https://docs.gravityforms.com/gform_field_validation | |
* @param array $result The validation result to be filtered. | |
* @param string $value The field value to be validated. Multi-input fields like Address will pass an array of values. | |
* @param object $form Current form object. | |
* @param object $field Current field object. | |
*/ | |
function ag_disable_urls_validation($result, $value, $form, $field) | |
{ | |
$nourl_pattern = '(http|https)'; // Looks for http and https. | |
if (preg_match($nourl_pattern, $value)) { | |
$result['is_valid'] = false; | |
$result['message'] = 'Message can not contain website addresses.'; | |
} | |
return $result; | |
} | |
add_filter('gform_field_validation', 'ag_disable_urls_validation', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment