Password Confirmation Elementor Pro Form

// Validate Confirmation password

add_action( 'elementor_pro/forms/validation', function ( $record, $ajax_handler ) {

$form_name = $record->get_form_settings( 'form_name' );

// Replace MY_FORM_NAME with the name you gave your form

if ( 'MY_FORM_NAME' !== $form_name ) {
return;
}

//Replace MY_FIELD_ID_1 to match the field's Advanced > Field ID

$first_pw_field = $record->get_field( [
'id' => 'MY_FIELD_ID_1 '
] );

//Replace MY_FIELD_ID_2 to match the field's Advanced > Field ID

$second_pw_field = $record->get_field( [
'id' => 'MY_FIELD_ID_2 '
] );

//Make sure your field ID's are set to match these in each field's Advanced > Field ID
if ( $first_pw_field['MY_FIELD_ID_1 ']['value'] !== $second_pw_field['MY_FIELD_ID_2 ']['value'] ) {
$ajax_handler->add_error( $second_pw_field['MY_FIELD_ID_2 ']['id'], 'Confirmation password must match the password field' );
}

}, 10, 2 );

Related Articles