Im making custom account page, and setting up lost/forgot password . I have form with “Lost password” action, that sends link to reset password. And when i follow that link on my password Reset page i have form with 2 fields: New Password and Repeat New Password. When i select action “Reset Password” . New menu apears and in dropdown it lets me pick wich field to select as “New password” it will set.
Issue is it doesnt check if New Password field matches Repeat New Password field.
I’m also interested in how to do this. I feel as if there should be a validation step that can compare the two “new password” fields match, as it ensures a user has entered the desired new password correctly. Is there any way to have the fields checked? Maybe that’s an action that needs to be added?
// Skip validation if form id doenst match.
if ( $form_id != 'xierpf' ) {
// Early return the $errors array if it's not the target form
return $errors;
}
// New validation for form ID 'xierpf'
if ( $form_id === 'xierpf' ) {
// Get submitted field values for the new password and repeat password fields
$new_password = $form->get_field_value( 'a7b70b' );
$repeat_password = $form->get_field_value( 'nvtkuz' );
// Check if the passwords match
if ( $new_password !== $repeat_password ) {
// Add error message to the $errors message array
$errors[] = esc_html__( 'The passwords you enter do not match. Please try again.', 'bricks' );
}
}
// Make sure to always return the $errors array
return $errors;
}, 10, 2 );
This is what i eventually did, and it seems to work as intended. Replace Form ids and field ids with your form corresponding fields.
I am just now circling back to try this again. Didn’t have any luck on my end using your example code. I’m not getting any form validation issue on my end, the password just gets reset even if the fields don’t match.
Is this solved now? Not sure how to set it up, though i can see the UI has some considerations for these forms now it’s not obvious how to do it for password resets. There is not a matching password field anymore - does it do this automatically if there are two fields?