• I’m try to implement the below solutions to show custom messages for validation (like email field).

    But, the form only shows error messages from “Messages” tab and looks like this hook doesn’t even call the function when I click form submit button:

    functions.php

    add_filter( ‘wpcf7_validate_email’, ‘custom_email_validation’, 10, 2 );

    function custom_email_validation( $result, $tag ) {
    $type = $tag->type;
    $name = $tag->name;
    if($type == ’email’ && $_POST[$name] != ”) {
    if(substr($_POST[$name], 0, 1) == ‘.’ ||
    !preg_match(‘/^[A-Za-z0-9.]+@(?:[A-Za-z0-9-]+\.){1,2}[A-Za-z]{1,}+$/’, $_POST[$name])) {
    $result->invalidate( $tag, wpcf7_get_message($name) );
    }
    }
    if($type == ‘text*’ && $_POST[$name] != ”){
    if(!preg_match(‘/^[A-Za-z.]+$/’, $_POST[$name])){
    $result->invalidate( $tag, wpcf7_get_message( $name ) );
    }
    }
    return $result;
    }

    I tried adding console.log(1); to see if it works, and looks like it just not firing on this hook. Any help?

    • This topic was modified 7 years, 1 month ago by igord.

The topic ‘wpcf7_validate_email Hook doesn’t fire’ is closed to new replies.