In Drupal 4.6, when user_login() outputs the login form, it uses the code:
return form($output, 'post', url('user/login', drupal_get_destination()));
This sends the user to back to the current page after logging in. This works well for the standard User Login block which appears on normal pages and displays a user/pass/submit form.
I have a custon User Login block which just has a "Log in" text link which points to "user" to generate a page containing only the login form. I can add a destination query to my link but the code above doesn't use it; it always sends the user back to the "user" page after logging in, instead of back to the page on which they clicked "Log in".
I fixed this by having user_login() propagate the destination query if it is present:
if ($_REQUEST['destination']) {
$dest = 'destination='.urlencode($_REQUEST['destination']);
} else {
$dest = drupal_get_destination();
}
return form($output, 'post', url('user/login', $dest));
This works fine. Is there any reason drupal_get_destination() should not ALWAYS do this? Is 4.7 any different?
Thanks,
Barry
Comments
bug
i think this is a bug. the behavior you describe is what is expected. there is probably an open issue on this already
if you'd like to make this fix yourself...
the first line of code referenced above can be found in the file "modules/user.module" around line 850 and should be replaced with the second block of code.