• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

WordPress Tips and Tricks

  • Home
  • WordPress Tutorials
  • Useful Links

Prevent Links in Gravity Forms Paragraph Text Field

Home - Code Snippets - Prevent Links in Gravity Forms Paragraph Text Field

December 27, 2020 by wptricks

I was having an issue with link spam in a Gravity Forms paragraph text field. Here is a code snippet that validates the field and prevents link submissions.

Place the code in your theme’s functions.php file. Replace ‘[form number]’ with your form number. Replace ‘[field number] with the field number.

// add custom validation to form
add_filter( 'gform_field_validation_[form number]_[field number]', 'validate_text_1_4', [form number], [field_number] );
function validate_text_1_4( $result, $value, $form, $field ) {
	$nourl_pattern = '(http|https)';
	if ( preg_match( $nourl_pattern, $value ) ) {
		$result['is_valid'] = false;
		$result['message']  = 'Message can not contain website addresses.';
	}
	return $result;
}
Category: Code SnippetsTag: Gravity Forms
Previous Post:Meta Description on Pages
Next Post:CSS { In Real Life }

Sidebar

Recent Posts

  • Truncate Text with CSS
  • CSS { In Real Life }
  • Prevent Links in Gravity Forms Paragraph Text Field
  • Meta Description on Pages
  • Find Out Which Host a Website is On

Categories

  • Code Snippets
  • Design Resources
  • Fonts
  • SEO
  • Tutorials
  • Uncategorized
  • Useful Links
  • WooCommerce

A Few of Our Favorite Products


Copyright © 2023 · WordPress Tips and Tricks · All Rights Reserved

Back to top