• Hello,

    using this code:

    add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
    
    functioncustom_email_confirmation_validation_filter( $result, $tag) {
    
    ??if( 'your-email-confirm'== $tag->name ) {
    
    ????$your_email= isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
    
    ????$your_email_confirm= isset( $_POST['your-email-confirm'] ) ? trim( $_POST['your-email-confirm'] ) : '';
    
    ????if( $your_email!= $your_email_confirm) {
    
    ??????$result->invalidate( $tag, "Are you sure this is the correct address?");
    
    ????}
    
    ??}
    
    ??return$result;
    
    }

    would it be possibile to make the confirmation e-mail field mandatory to fill in only if the email field is filled in (which is therefore optional)?

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Isn’t the main your-email field mandatory?

    Thread Starter Simo2606

    (@simo2606)

    Hello,

    yes, it is not mandatory; the your-email-confirm field should be mandatory only of the user fill in the email field, is it possible?

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Then let the your-email-confirm field use the email (not email*) tag type as well as the your-email field does, and code the mandatory validation logic in your validation filter function.

    See Custom validation for details.

    Thread Starter Simo2606

    (@simo2606)

    The problem is the following: the email field is not mandatory, if the user fills it in, the email confirmation field will also not be mandatory (following the logic of the email field), so the user will be able to continue without validation. Is there a way to make the email confirmation field mandatory only when the user has filled out the email field? Otherwise there is no point in inserting a validation field if the user can then continue without having filled it in.

    Thank you very much

    • This reply was modified 6 months, 2 weeks ago by Simo2606.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Email field validation’ is closed to new replies.