Login form - hook_form_alter destinations broken I have a custom log in template along with some alterations. It seems to work just fine everywhere except where I have ...?destination=foo/bar.

The template code is:

&lt;div id="fdanconia_login"&gt;
  &lt;div id="fdanconia_login_form"&gt;
    &lt;?php print render(drupal_get_form('user_login', $form)); ?&gt;
  &lt;/div&gt;
  &lt;div class="register_now"&gt;Don't have an account? &lt;b&gt;Register now&lt;/b&gt;&lt;/div&gt;
  &lt;div id="fdanconia_register_form"&gt;
    &lt;?php print render(drupal_get_form('user_register_form')); ?&gt;
  &lt;/div&gt;
&lt;/div&gt;


The module code is:

function fdanconia_menu(){
  $items['login'] = array(
    'title' =&gt; 'Login',
    'page callback' =&gt; '_fdanconia_login',
    'access callback' =&gt; true,
  );
  return $items;
}

function fdanconia_theme(){
  $themes = array(
    'fdanconia_login' =&gt; array(
      'template' =&gt; 'fdanconia_login',
      'arguments' =&gt; array(),
    ),
  );
  return $themes;
}

function fdanconia_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  switch ($form_id) {
    case 'user_login':
      // Redirect users to the new login page
      if (isset($_GET['destination']) &amp;&amp; $destination = $_GET['destination']) {
        $options = array('query' =&gt; array('destination' =&gt; $destination));
        unset($_GET['destination']);
      } else {
        $options = array();
      }
      if (arg(0) == 'user' &amp;&amp; !$user-&gt;uid) drupal_goto('login', $options);
      $form['name']['#description'] = 'Email';
      $form['pass']['#description'] = 'Password';
    break;
    case 'user_register_form':
      if (arg(0) == 'user' &amp;&amp; !$user-&gt;uid) drupal_goto('login', array('query' =&gt; array('destination' =&gt; $destination)));
      $form['account']['name']['#type'] = 'hidden';
      array_unshift($form['#validate'], '_fdanconia_login_validate');
    break;
  }
}

function _fdanconia_login() {
  drupal_add_css(drupal_get_path('module', 'fdanconia') . '/fdanconia.css');
  drupal_add_js(drupal_get_path('module', 'fdanconia') . '/fda.js', 'file');
  return theme('fdanconia_login');
}

function _fdanconia_login_validate($form, &amp;$form_state) {
  $email = $form_state['values']['mail'];
  $form_state['input']['name'] = $email;
  $form_state['values']['name'] = $email;
  $form_state['complete form']['account']['name']['value'] = $email;
}


So, when I log in with a destination no matter what it redirects to the default log in page as if there were no destination parameter. However, the destination shows up in the URL. I can even manually put a destination in the URL and when I submit the form, I am not redirected to the proper destination. There is nothing in watchdog about the log in other than a session has been created.

What is going wrong here?
I think in D7 you can also use the redirect property, this would be in your form_alter:

  $form_state['redirect'] = array('http://www.example.com/my-external-path', array('external' =&gt; TRUE));


$form_state['redirect'] takes the same values as drupal_goto(), which itself uses url() to generate its destination path. It is possible to add an array of options including 'external=TRUE' to your redirect value if redirect is external.

Not sure if this will help in your case though.