• Milamber

    (@milamber)


    The following function is causing IE’s popup blocker (v8-10 – Internet domain default security settings) to trigger on any form submission that uses the company-email field and passes validation. Immediately following the user is redirected to the form’s action url.

    Swapping company-email for your-email in the form immediately corrects the issue.

    // Add custom validation for CF7 form fields
    function is_company_email($email){ // Check against list of common public email providers & return true if the email provided *doesn't* match one of them
    	if(
    		preg_match('/@gmail.com/i', $email) ||
    		preg_match('/@hotmail.com/i', $email) ||
    		preg_match('/@live.com/i', $email) ||
    		preg_match('/@msn.com/i', $email) ||
    		preg_match('/@aol.com/i', $email) ||
    		preg_match('/@yahoo.com/i', $email) ||
    		preg_match('/@inbox.com/i', $email) ||
    		preg_match('/@gmx.com/i', $email) ||
    		preg_match('/@me.com/i', $email)
    	){
    		return false; // It's a publicly available email address
    	}else{
    		return true; // It's probably a company email address
    	}
    }
    
    function custom_email_validation_filter($result,$tag){
    	$type = $tag['type'];
    	$name = $tag['name'];
    
    	$_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
    
    	if('company-email' == $name){ // Only apply to fields with the form field name of "company-email"
    		if(!is_company_email( $_POST[$name] )){ // Isn't a company email address (it matched the list of free email providers)
    			$result['valid'] = false;
    			$result['reason'][$name] = 'You need to provide an email address that isn\'t hosted by a free provider.<br />Please contact us directly if this isn\'t possible.';
    		}
    	}
    	return $result;
    }
    add_filter('wpcf7_validate_email','custom_email_validation_filter', 11, 2); // Email field
    add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 11, 2); // Req. Email field

    Above code is a slightly modified version of: http://wordpress.org/support/topic/plugin-contact-form-7-custom-field-validation-code#post-2442585

    I’ve compared the above code to that found in CF7’s /modules/text.php and can find no reason why it would be triggering a response different from wpcf7_text_validation_filter

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wpcf7_validate_email triggering IE popup blocker’ is closed to new replies.