• Resolved flatword

    (@flatword)


    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/

    */

    functionwpf_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]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @flatword,

    Thank you for reaching out!

    The code snippet in our guide How to Block URLs Inside the Form Fields worked as expected in my test. For your reference, here’s a screencast demonstrating the setup.

    If possible, could you try applying the code again using the WPCode plugin, following the steps in the screencast?

    Let me know if this works for you or if there’s anything further I can assist with!

    Thread Starter flatword

    (@flatword)

    Thank you @rsouzaam.

    I had been trying the instructions in that post for well over an hour. If you read that post, it says to refer to another post

    If you need help in adding snippets to your site, please see this tutorial.

    So in that post you will see

    Next, you’ll see the Insertion section. Since we’re adding PHP, we’ll select Auto-Insert for the Insert Method and Frontend Only for the Location.

    The problem is that you don’t see it to Frontend Only…you leave it set to its default of “Run Everywhere”.

    So while that first post is great for providing the PHP code, the article which it references was not accurate.

    Perhaps you can update one of these 2 posts to mention the proper snippet location to run.

    Thank you again for your reply. The screencast you made give me the answer because even though you did not show the setting at the bottom of the snippet, since you didn’t set it then it was obvious it should be left as the default…which is “Run Everywhere?

    • This reply was modified 2 weeks, 2 days ago by flatword.
    Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @flatword,

    Thank you for your feedback on our documentation!

    The Frontend Only option is appropriate for the code snippet above the sentence you referenced in our guide, How to Add Custom PHP or JavaScript for WPForms. However, this option doesn’t work for all code snippets.

    For the wpforms_process_validate hook, it’s recommended to use the Run Everywhere option.

    I’ll report this to our team so they can review the guide to make it more accurate.

    If you’d like further assistance with WPForms Lite, please don’t hesitate to reach out.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.