function UserPasswordForm::submitForm

Same name and namespace in other branches
  1. 8.9.x core/modules/user/src/Form/UserPasswordForm.php \Drupal\user\Form\UserPasswordForm::submitForm()
  2. 10 core/modules/user/src/Form/UserPasswordForm.php \Drupal\user\Form\UserPasswordForm::submitForm()
  3. 11.x core/modules/user/src/Form/UserPasswordForm.php \Drupal\user\Form\UserPasswordForm::submitForm()

Overrides FormInterface::submitForm

File

core/modules/user/src/Form/UserPasswordForm.php, line 207

Class

UserPasswordForm
Provides a user password reset form.

Namespace

Drupal\user\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $account = $form_state->getValue('account');
    if ($account) {
        // Mail one time login URL and instructions using current language.
        $mail = _user_mail_notify('password_reset', $account);
        if (!empty($mail)) {
            $this->logger('user')
                ->notice('Password reset instructions mailed to %name at %email.', [
                '%name' => $account->getAccountName(),
                '%email' => $account->getEmail(),
            ]);
        }
    }
    else {
        $this->logger('user')
            ->notice('Password reset form was submitted with an unknown or inactive account: %name.', [
            '%name' => $form_state->getValue('name'),
        ]);
    }
    // Make sure the status text is displayed even if no email was sent. This
    // message is deliberately the same as the success message for privacy.
    $this->messenger()
        ->addStatus($this->t('If %identifier is a valid account, an email will be sent with instructions to reset your password.', [
        '%identifier' => $form_state->getValue('name'),
    ]));
    $form_state->setRedirect('<front>');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.