Skip to content

Instantly share code, notes, and snippets.

@mjones129
Created February 26, 2024 18:55
Show Gist options
  • Save mjones129/8135bb5a9e4b47e163b996d0d5da3b67 to your computer and use it in GitHub Desktop.
Save mjones129/8135bb5a9e4b47e163b996d0d5da3b67 to your computer and use it in GitHub Desktop.
Filter URLs from Gravity Forms Comment Box or Text Area
<?
//prevent gravity forms submissions containing URLS
//filter hook 'gform_field_validation_1_12' identifies a Gravity Form with an ID of 1 and a Field ID of 12
//second argument for the filter can be anything, it's just referencing the name of the function to run
add_filter( 'gform_field_validation_1_12', 'validate_input_1_12', 10, 4 );
function validate_input_1_12( $result, $value, $form, $field ) {
$nourl_pattern = '(ftp|http|https|www|.com|.net|.org|.io|.biz|.info|.mil|.edu|.gov|.me|.int|FTP|HTTP|HTTPS|WWW|.COM|.NET|.ORG|.IO|.BIZ|.INFO|.MIL|.EDU|.GOV|.ME|.INT)';
if (preg_match( $nourl_pattern, $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'Your message cannot contain hyperlinks.';
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment