I need the user,opening a certain page of my site (www.foo.com/page_to_visit), to login and then go to the requested page, so I set up an hook_menu for this specific page and a callback. In the callback I added this code which works

drupal_goto('user', array('query'=>drupal_get_destination()))

but if the url contains query strings (www.foo.com/page_to_visit?id=12&od=12) they are removed. I mean that, after login, the user gets redirected to www.foo.com/page_to_visit instead of www.foo.com/page_to_visit?id=12&od=12. How do I avoid this behaviour?

UPDATE: Drupl_goto has something supporting this. Produced this code, following documentation

$args = array();
$params = $_GET;
$args[] = $params['q'];
unset($params['q'], $params['destination']);
if (count($params) > 1) {
  $pippo['query'] = $params;
  $args[] = $pippo;
drupal_goto('user', array('query'=>$args));

$args results in --->
( [0] => page_to_visit
  [1] => Array
    ( [query] => Array
            ( [id] => 12 
              [od] => 12

The result is odd for the redirect looks like http://www.foo.com/user?0=page_to_visit&1[query][id]=12&1[query][od]=12

  • 1
    Have you tried out the LoginToboggan module? It might handle the passing of query string after login but I can't be sure. Half the problem is that the login destination is already being passed as a query string: drupal.org/node/1671118 Feb 4, 2016 at 14:58
  • Surely I'll try. The problem lies exactly there... Feb 4, 2016 at 16:12

2 Answers 2


I think, my suggestion is :-

  1. alter login form
  2. add a hidden field for destination URL.
  3. add submit handler like $form['#submit'][] = 'destination_redirect_handler'
  4. use drupal_goto('destination_redirect_url') in this destination_redirect_handler

Modify your call to drupal_goto() like this:

drupal_goto('user', array('query'=>drupal_http_build_query($args)));

drupal_http_build_query() builds a formatted query string from an array.

Hope this helps.


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.