Code to stop urls in form field not working
-
Hi,
I am using wpform lite.
I am following the instructions on this page https://wpforms.com/developers/how-to-block-urls-inside-the-form-fields/ and using the WPCode plugin to add the below code set to AutoInsert Front-End Only. I have 1 page with 1 form but when I submit, I can still submit “http” and “www.” submissions in the textarea field (also see below).
<textarea id=”wpforms-293-field_2″ class=”wpforms-field-small” name=”wpforms[fields][2]” aria-errormessage=”wpforms-293-field_2-error” ></textarea>/*
* 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 );
If I add this to the bottom of that snippet, I do see the word “fired” in the console output.
// Add a script to log the message to the console add_action(‘wp_footer’, function() { ?> <script type=”text/javascript”> console.log(“fired”); // Confirm this fires at the footer </script> <?php });
I have tried every suggestion thrown out to me by 2 different AI chats. ??
Any ideas on what would work to stop urls from being allowed in my textarea field?
Thank you
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.