Forked from adriannees/elementor_email_validation.php
Created
November 15, 2024 14:56
-
-
Save dexit/94ab5f6dd91702e92389a43284392202 to your computer and use it in GitHub Desktop.
Elementor Form Email Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Validate confirmation email ref (https://github.com/elementor/elementor/issues/8684) | |
add_action( 'elementor_pro/forms/validation', function ( $record, $ajax_handler ) { | |
// Create variables representing the field ids of the fields | |
$first_email_field = $record->get_field( ['id' => 'email'] ); // Field ID (Advanced tab) is "email" | |
$second_email_field = $record->get_field( ['id' => 'email_confirm'] ); // Field ID (Advanced tab) is "email_confirm" | |
if ( property_exists( $second_email_field ) ) { | |
//Make sure your field ID's are set to match these in each field's Advanced > Field ID | |
if ( $first_email_field['email']['value'] !== $second_email_field['email_confirm']['value'] ) { | |
$ajax_handler->add_error( $second_email_field['email_confirm']['id'], 'Whoops. The emails you entered do not match. Try again' ); | |
} | |
// Otherwise return the form without validation | |
return; | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment