Created
March 14, 2023 18:54
-
-
Save LittleMikeNZ/def87bf612b96f4f98c278fc8c89e1f4 to your computer and use it in GitHub Desktop.
Wordpress/WPForms: How to Block URLs Inside the Form Fields
This file contains hidden or 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
/* | |
* Block URLs from inside form on Single Line Text and Paragraph Text form fields | |
* | |
* @link https://wpforms.com/developers/how-to-block-urls-inside-the-form-fields/ | |
*/ | |
function wpf_dev_check_for_urls( $field_id, $field_submit, $form_data ) { | |
if( strpos($field_submit, 'http') !== false || strpos($field_submit, 'www.') !== false ) { | |
wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'No URLs allowed.', 'wpforms' ); | |
return; | |
} | |
} | |
add_action( 'wpforms_process_validate_textarea', 'wpf_dev_check_for_urls', 10, 3 ); | |
add_action( 'wpforms_process_validate_text', 'wpf_dev_check_for_urls', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment