0

I want to alter the redirect of UserPasswordForm from Drupal’s core, I did this

function maubl_user_form_alter(&$form, FormStateInterface $form_state, $form_id){
switch($form_id) {
case 'user_pass':
    $form['actions']['submit']['#submit'][] = 'maubl_user_submit_forgot_pass';
    break;
}
function maubl_user_submit_forgot_pass(&$form, \Drupal\Core\Form\FormStateInterface $formState){

  $formState->setRedirect('<front>');

}

It does do the redirect correctly, but the submit from UserPasswordForm doesnt excute anymore, so the mail doesnt get sent, does anyone know why and how I can fix that ?

0

By adding a submit handler to the submit element you override the main submit handler attached to the form. The use case for this option is if you want a submit element to have a completely different action.

Append your submit handler to the form and it should work as you have intended:

$form['#submit'][] = 'maubl_user_submit_forgot_pass';
  • Thank you! Worked like a charm. – StefanYYC Dec 6 '19 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.