Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dexit/94ab5f6dd91702e92389a43284392202 to your computer and use it in GitHub Desktop.
Save dexit/94ab5f6dd91702e92389a43284392202 to your computer and use it in GitHub Desktop.
Elementor Form Email Validation
// 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