• Hello,

    We are using Contact Form 7 latest version (5.6.3) on our site and when we try to add custom validation using hooks, it doesn’t work for empty field validation. The hooks work fine when we roll back the plugin version to 5.5.6.1.

    Here am attaching the screenshot of the forms. this is a screenshot for version 5.6.3 https://snipboard.io/cSusk3.jpg and this is for version 5.5.6.1 https://snipboard.io/obIpS9.jpg.

    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'];
             
              if($value==''){
                
                $result->invalidate($tag, "Please enter your name.");
            }
        }
     return $result;
    
    }

    kindly please check the custom validation message issue for empty fields.

    Thanks.

    • This topic was modified 2 years, 6 months ago by navasahmed.
  • The topic ‘Custom validation Message not working for empty field’ is closed to new replies.