Skip to content

Instantly share code, notes, and snippets.

@taricco
Created April 29, 2022 17:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save taricco/beb1e8bb53010eaef4b63aa5242c9885 to your computer and use it in GitHub Desktop.
@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