Email Validation filter function on two forms
-
Hello all,
I’m using two CF7 forms on a single WP website – Form 1 and Form 2 – for which users are requested to fill in an email address. For validation purposes I ask them to repeat their email address (to eliminate/reduce the risk of typos) and use the filter function used for the validation as described here:
https://contactform7.com/2015/03/28/custom-validation/
Form 1 uses the following email name tags:
<label> Email-Address [email* your-email-1 autocomplete:email placeholder "Your Email-Address"] </label> <label> Repeat Email-Address [email* your-email-confirm-1 autocomplete:email placeholder "Please repeat your Email-Address"] </label>
and Form 2 uses these email name tags:
<label> Email-Address [email* your-email-2 autocomplete:email placeholder "Your Email-Address"] </label> <label> Repeat Email-Address [email* your-email-confirm-2 autocomplete:email placeholder "Please repeat your Email-Address"] </label>
In the theme functions.php I have added the following filter function taken from the contactform7 website (see link above) for validating the email address in Form 1. That’s working perfectly fine.
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 ); function custom_email_confirmation_validation_filter( $result, $tag ) { if ( 'your-email-confirm-1' == $tag->name ) { $your_email = isset( $_POST['your-email-1'] ) ? trim( $_POST['your-email-1'] ) : ''; $your_email_confirm = isset( $_POST['your-email-confirm-1'] ) ? trim( $_POST['your-email-confirm-1'] ) : ''; if ( $your_email != $your_email_confirm ) { $result->invalidate( $tag, "Please check your Email-Address" ); } } return $result; }
How would I amend the filter function above in order to add the same email validation in form 2 with the name tags below (and have the function keep working in Form 1)?
[email* your-email-2] and [email* your-email-confirm-2]
Any help greatly appreciated!
Thank you very much!
- The topic ‘Email Validation filter function on two forms’ is closed to new replies.