3

I have added the login form to a page using drupal_get_form. Now, I would like to redirect the users back to that page after login. Note: I don't want to redirect users that logged in somewhere else (e.g. user/login), and I also don't want to use a contib module for that.

B.T.W Maybe if I'll Ajaxify the login form it will have the same effect?

I'll appericiate any help and/or examples.

Thanks!

5

You have to add form_alter and add custom #submit handler to user_login form if current_path() is correct for you and set $form_state['redirect'] there.

Check this post Redirect to a custom page after a node has been added or edited.

Also it can be achieved via custom rule, if you don't want to write any custom code.

  • It's not working because I'm using drupal_get_form() to get the form on my theme, and I don't want to use hook_form_alter because it will also redirect from the primary login form. – rreiss Nov 20 '13 at 18:03
  • 1
    You can pass your own custom flag, for example drupal_get_form($form_id, array('use_custom_redirect' => TRUE)) and then use this argument in form_alter - if ($form_state['build_info']['args']['use_custom_redirect']) {...} – m1r1k Nov 20 '13 at 23:31
0

You should save the current path and use that current path in the redirect path of the form

$redirect_url = current_path();
$form['#redirect'] = $redirect_url;

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.