Support » Plugin: Contact Form 7 » Field Validation No Longer Works

  • Resolved Michael Simpson


    Contact Form 7 version 4.1

    I created a simple case to demonstrate:


    <p>Your Email [email* example-email] <br/>
    [submit "Send"]</p>

    Then I add a validation hook on the “example-email” field. In this example, it should reject all emails except for

    function example_email_validation($result, $tag) {
       $example_log_file = '/path/to/your/validate_email.txt';
        error_log("Validation called with {$tag['name']}\n", 3, $example_log_file);
        $fieldName = 'example-email'; // field on the form
        if($fieldName == $tag['name']){ // this is the field
            $email = $_POST[$fieldName];
            if ($email != '') { // would put actual validation here. Hard coding for example.
                $result['valid'] = false;
                $result['reason'][$fieldName] = 'Invalid Email'; // error message
                error_log("Failed Validation: $email \n", 3, $example_log_file); // debug
            } else {
                error_log("Passed Validation: $email \n", 3, $example_log_file); // debug
        return $result;
    add_filter('wpcf7_validate_email*', 'example_email_validation', 10, 2);
    add_filter('wpcf7_validate_email', 'example_email_validation', 10, 2);

    I do 2 submissions, one with a valid email and one without. The log file reports as expected:

    Validation called with example-email
    Passed Validation:
    Validation called with example-email
    Failed Validation:

    But even when the validation fails, the Form UI reports success: “Your message was sent successfully. Thanks.” and I receive an email for both the valid and invalid submissions.

    It appears that the return value is ignored. Or has the API changed?

    This functionality is important to a number of people using CFDB with CF7 where they use a validation like this to prevent duplicate submissions.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Field Validation No Longer Works’ is closed to new replies.