Extending Contact Form 7: custom validation not working
-
I’m using add_filter to hook in and add extra validation but nothing happens on the front end at all. It all gets ignored. What am I doing wrong?
Code:
function my_wpcf7_validate_text($result,$tag) { if($name == 'CANZipCode') { $CANZipCode = $_POST['CANZipCode']; if($CANZipCode != '') { if(!preg_match('/^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/', $CANZipCode)) { $result['valid'] = false; $result['reason'][$name] = 'Entered Zipcode is Invalid'; } } } } add_filter('wpcf7_validate_text*', 'my_wpcf7_validate_text', 10, 2); // Req. text field add_filter('wpcf7_validate_text','my_wpcf7_validate_text', 10, 2); // text field
Then, in contact form 7’s admin page:
[text* CANZipCode]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Extending Contact Form 7: custom validation not working’ is closed to new replies.