How to Set up Reset Password form Validations?!

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.

How To Fix This ??

image

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?

add_filter( ‘bricks/form/validate’, function( $errors, $form ) {
$form_settings = $form->get_settings();
$form_fields = $form->get_fields();
$form_id = $form_fields[‘formId’];

// 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.

1 Like

@AlexArtix, can you tell me where you find the form ID? I know there to find the field IDs, but I’m not sure about the individual form’s ID.

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.