• Resolved navasahmed

    (@navasahmed)


    Hello,

    We are using Contact Form 7 latest version (5.6.1) on our site and when we try to add custom validation using hooks, it doesn’t work. When we rollback the plugin version to 5.5.6.1, the hook works. We need to resolve the issue as soon as possible, so please check the issue and let me know how we can resolve it.

    I have attached the sample code I have added to my site:

    add_filter('wpcf7_validate_text', 'custom_text_validation', 1, 2);
    add_filter('wpcf7_validate_text*', 'custom_text_validation', 1, 2);
    function custom_text_validation($result, $tag) {
        $type = $tag->type;
        $name = $tag->name;
        
        if($name == 'text-566') {
            $value = $_POST['text-566'];
             $len= strlen($value);
              if($value==''){
                
                $result->invalidate($tag, "Please enter your name.");
            }
                
            
           
         if( !preg_match( '/^([a-zA-Z ]|[\p{Arabic}]|[_])*$/u', stripslashes(str_replace( "'", "", $value))) ){
                
                $result->invalidate($tag, "Please make sure your name contains at least 3 characters that do not include any digits or special characters.");}
                
            if($len<3){
                $result->invalidate($tag, "Sorry, the name you entered is too short. Please make sure your name contains at least 3 characters");
            }
    
        }
        
         return $result;
    
    }
    
    add_filter('wpcf7_validate_email', 'custom_email_validation_filter', 1, 2);
    add_filter( 'wpcf7_validate_email*', 'custom_email_validation_filter', 1, 2 );
    
    function custom_email_validation_filter( $result, $tag ) {
       
        $tag = new WPCF7_FormTag($tag);
        //===Career form validation
        if ('Email' == $tag->name) {
            $value      = $_POST['Email'];
            if($value==''){
                $result->invalidate($tag, "Please enter your email address.");
            }
            // matches any utf words with the first not starting with a number
            $re = '/^[\w.-]+@[a-zA-Z_]+?\.([a-zA-Z]{2,3}|[a-zA-Z]{2,3}.[a-zA-Z]{2,3})$/i';
            if (!preg_match($re, $_POST['Email'], $matches)) {
                $result->invalidate($tag, "Sorry, the email address you entered doesn’t seem right. Can you please try again?");
            }
        }
        //===Career form validation ending
        
    
      return $result;
    
    }

    Thanks.

    • This topic was modified 2 years, 4 months ago by navasahmed.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    Thread Starter navasahmed

    (@navasahmed)

    Hello @takayukister,

    I have set up these codes on my local, so how i can share that. can you please try this code on your end?

    Thanks.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    OK. I looked through the code and found no problem in it. I don’t know your intention and what you mean by “not working”, though.

    Thread Starter navasahmed

    (@navasahmed)

    hello @takayukister,

    The empty field validation message not change to a custom validation message.

    Thanks

    Thread Starter navasahmed

    (@navasahmed)

    Hello @takayukister,

    Here am attaching the screenshot of the forms. this is a screenshot for version 5.6.1 https://snipboard.io/cSusk3.jpg and this is for version 5.5.6.1 https://snipboard.io/obIpS9.jpg. kindly please check the custom validation message issue for empty fields.

    Thanks.

    Thread Starter navasahmed

    (@navasahmed)

    Hello @takayukister,

    any updates on the above query?

    Thanks

    Thread Starter navasahmed

    (@navasahmed)

    Hello @takayukister,

    Any Update?

    Thanks.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    I replied to you two weeks ago. What are you waiting for?

    Stop abusing @<name> mentions.

    Thread Starter navasahmed

    (@navasahmed)

    hello,

    I have responded to your reply. You didn’t notice that. Please let me know what the issue is, and I have attached a screenshot.

    Here is the message I sent previously.

    “Here am attaching the screenshot of the forms. this is a screenshot for version 5.6.1 https://snipboard.io/cSusk3.jpg and this is for version 5.5.6.1 https://snipboard.io/obIpS9.jpg. kindly please check the custom validation message issue for empty fields.”

    Thanks

    Thread Starter navasahmed

    (@navasahmed)

    I apologize for mentioning your name, I thought it would receive a fast response.

    Please Check the empty field value error message. Please add this code to your site and check it. The difference between the latest version and version 5.5.6.1 can be seen then.

    add_filter('wpcf7_validate_text', 'custom_text_validation', 1, 2);
    add_filter('wpcf7_validate_text*', 'custom_text_validation', 1, 2);
    function custom_text_validation($result, $tag) {
        $type = $tag->type;
        $name = $tag->name;
        if($name == 'Name') {
            $value = $_POST['Name'];
             $len= strlen($value);
              if($value==''){
                
                $result->invalidate($tag, "Please enter your name.");
            }
        }
     return $result;
    
    }

    Thanks

    • This reply was modified 2 years, 3 months ago by navasahmed.
    Thread Starter navasahmed

    (@navasahmed)

    Hi,

    Did you check my reply above? please check that and give an update.

    Thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom validation not working on latest version’ is closed to new replies.