0

I know there are a couple modules other there that handle login redirects like Login Destination, LoginToboggan, Login Redirect and Rules. However, they all seem to only allow strict URLs. I would like users to be redirected to the same page they logged in on. The default behaviour of Drupal appears to redirect users to the previous page on login.

Since I am using a login modal, redirecting people to the previous page doesn't work well.

How can I redirect users to their current page when using a login modal that handles the login through AJAX? I would appreciate a solution that could be placed in template.php maybe using hook_user_login()

1

Take a look at the implementation in user_login_block(), particularly this line:

$form['#action'] = url(current_path(), array('query' => drupal_get_destination(), 'external' => FALSE));

This will add the destination parameter to the URL, which takes precedence over any other arguments passed to drupal_goto() (like $form_state['redirect']).
Depending on how you create your modal, the easiest way would therefore be to simply append the destination argument for the current page to the form action.

  • My current user_login_block() looks like this: $form['actions']['submit']['#ajax'] = array( 'callback' => '_bootstrap_login_modal_ajax_callback', 'wrapper' => 'ajax-' . $html_id . '-wrapper', 'event' => 'click', ); – VanD Oct 2 '15 at 16:06

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.