Custom validation not working on latest version
-
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.
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Custom validation not working on latest version’ is closed to new replies.