I've been trying to redirect the password reset page to my custom login page by creating a small custom module; however it's not resolving properly.

Has anyone done this before with success? The code that I'm trying to use is:

function m2f_password_reset_form_alter(&$form, &$form_state) {
  if ($form['#action'] == "/user/password"){
    $form['#submit'][] = 'user-pass';
* Redirects user after password reset form is filled
function m2f_password_redirect(&$form, &$form_state){
  $form_state['redirect'] = 'node/20';

2 Answers 2


There are at least three possible issues that I can see:

  • You are probably not prefixing the function with the right string.
    If the module/theme name is m2f_password, then m2f_password_reset_form_alter() is not recognized at implementation of hook_form_alter().

  • If you are trying to alter the form that is shown at user/password, you should not check $form['#action']; you should implement hook_form_FORM_ID_alter(), and write a function called m2f_password_form_user_pass_alter(). (I assume the short name of the module/theme is m2f_password; if it is not correct, replace m2f_password with the short name of the module/theme.)

  • user-pass is not a valid form submission callback name: PHP functions cannot contains hyphens. You are then defining m2f_password_redirect(), and that seems a form submission callback.
    The correct code is probably the following one.

    $form['#submit'][] = 'm2f_password_redirect';

The problem is probably here:

$form['#submit'][] = 'user-pass';

The string that you add to the $form['#submit'] array must be a the name of a valid, existing PHP function. It's likely you just need to change that line to:

$form['#submit'][] = 'm2f_password_redirect';

Don't forget that PHP function names can't contain hyphens so user-pass would never be a valid name for a submit handler.

  • I understand, and have updated, but it's still not pulling through. m2f_ is the theme name, correct? I have the suspicion that there is something small that I'm overlooking. Thanks for your input/advice! For reference, I've been trying to follow this page: drupal.org/node/1458894
    – Ryan
    Commented Jun 28, 2012 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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