1

By default, if user submit his email in form at /user/password page, he will recieve an email with one-time login link. After opening this link he is redirected to page with form with one single "login" button - id of this form is user_pass_reset. After click on this button user is redirected to his profile in administrative part of a site: /user/X/edit where he can change his password.

But I have my own custom profile page, where users can change their password and I'd like to redirect user here instead of default profile in administration interface. I already found that user module is checking if old password is needed with this line:

$pass_reset = isset($_SESSION['pass_reset_' . $account->uid]) && isset($_GET['pass-reset-token']) && ($_GET['pass-reset-token'] == $_SESSION['pass_reset_' . $account->uid]);

But I can't find out how to redirect user to my own form on user_pass_reset submit. If I alter this form and change '#action' paramter I get a message that says this one-time login link is invalid. If I add my own submit function $form['#submit'][] = 'activit_password_redirect'; and in this function I call drupal_goto('my/own/form/page') user is still redirected to default profile page.

Is it possible to change url of this form submit?

1

Use hook_form_alter, then add a $form['#redirect'] parameter with value as your custom user profile page.

OR append a destination query to the default form action url.

<default_action_url>?destination=<your_custom_user_profile_url>

I recommend the first option. It's the Drupal way.

  • It does not work... user module is redirecting to default profile page in submit handler by drupal_goto() function - line 142 of user.pages.inc file – Incredible Dec 7 '15 at 9:55
  • @Incredible , then you can override it by specifying custom function as you created $form['#submit'][] = 'activity_password_redirect'; , then add change this $form_state['#redirect'] value there. – Jyothish Dec 7 '15 at 10:18
  • I've tryed it but it does nothing. – Incredible Dec 7 '15 at 10:20
  • @Incredible , this method worked for me. Might be some minor issues, I can't say more until I get know how you implemented it. – Jyothish Dec 8 '15 at 5:16
  • 1
    @Incredible, oh that's too bad... Forgot to mention that there is a hook "hook_user_login" , one time login link regenerate a session for a user ID after a user clicked on it. So give a try with that too... – Jyothish Dec 8 '15 at 10:50

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.