• Resolved vipingarg

    (@vipingarg)


    I want the contact form to prevent submitting when the textarea message contains an URL. Is that possible?

Viewing 1 replies (of 1 total)
  • Thread Starter vipingarg

    (@vipingarg)

    Solution:

    function custom_textarea_validation_filter($result, $tag) {
    $type = $tag[‘type’];
    $name = $tag[‘name’];
    //here textarea type name is ‘message’
    if($name == ‘your-message’) {
    $value = $_POST[$name];
    if (preg_match(‘/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i’, $value)){
    $result->invalidate( $tag, “Avoid URLs & Links” );
    }
    }
    return $result;
    }
    add_filter(‘wpcf7_validate_textarea’,’custom_textarea_validation_filter’, 10, 2);
    add_filter(‘wpcf7_validate_textarea*’, ‘custom_textarea_validation_filter’, 10, 2);

Viewing 1 replies (of 1 total)

The topic ‘How to avoid URLs & code in text area?’ is closed to new replies.