I am working on a workflow to allow users to easily create accounts on the website and then be returned to the original destination page after registration. I am using LoginToboggan to show the login page when a user tries to access a restricted section. I pass the original destination path in the url (&Destination=ORIGINAL_PATH) and it works great as long as a user is logging in to an existing account and not registering a new one.

The problem is that as soon as you click "Create New Account" then the destination URL is lost. I have tried using Login Destination but that did not resolve the problem. After spending hours searching the forums I have not come up with a solution, any ideas?\

Example Workflow

  • Anonymous user tries to access restricted page
  • User presented with login form
  • If not registered then user clicks "Create New Account" link. <-- This is where the destination URL is lost
  • User Registers and is redirected to original destination.

Again, this works perfect if you simply login, but not if you have to click any links (tabs) on the user page.

Thanks for any help in trying to solve this!

Comments

vm’s picture

would globalredirect.module help in this case ?

3cwebdev’s picture

Thanks for the fast reply but I don't think Global Redirect will work for this problem. I have not used the module before, but looking through the documentation it doesn't appear to offer any help for this scenario. Thanks again though~

gforce301’s picture

Not sure the Global Redirect module would help in this instance.

The problem is preserving the destination in the $_GET when the user clicks the link for "Create New Account". There is not an obvious mechanism to pass this parameter along and I don't believe LoginToboggan or Login Destination has the ability to handle this case as you have stated.

One way that you can accomplish this is by using a custom url rewriter. There are 2 of them that you can implement:
http://api.drupal.org/api/function/custom_url_rewrite_inbound/6
http://api.drupal.org/api/function/custom_url_rewrite_outbound/6

If you implement the outbound version, you can detect the path 'user/register' check for a destination in the current path and if there is one set it in the options. This will actually make the "Create New Account" link have the "&destination=xxxxxxxx" put right in it.

3cwebdev’s picture

I wanted to be sure to come back and thank you for your response. I was not aware of the custom_url_rewrite_*** functions. I spent some time reading up on ...outbound and did much experimenting with in for my situation. Although very neat and potentially useful, it fif not work for this situation. There were several problems preventing the existing destination from being picked up and passed through option=>query.

The main problem was that I had set logon-toboggan to show the logon form on access denied pages. The caused the url in the browser to show one path (the one I need) but drupal and the function to read another path (user/logon). In the end I simply used drupals error settings to send 403's to the path user/register and this retained the destination. I still faced with the same problem if someone clicks 'logon' from here but pertaining the destiantion after a user registers was the most important.

It seems like drupal would/should have a mechanism to handle retaining the original destination after user registers or logs on.

Anyway, thank you for you help.

gforce301’s picture

I thought for sure you would be able to make it work with one of the custom url rewrite functions. If I come across anything else in my wanderings I will let you know.

ultimike’s picture

This is possible using a hook_form_alter() in a custom module. Here's how I did it:

function yourmodule_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
      if (isset($_REQUEST['destination'])) {
        $_SESSION['yourmodule_register_redirect'] = $_REQUEST['destination'];
      }
      break;
      
    case 'user_register':
      if (isset($_SESSION['yourmodule_register_redirect'])) {
        $form['#redirect'] = $_SESSION['yourmodule_register_redirect'];
        unset($_SESSION['yourmodule_register_redirect']);
      }
      break;
  }
}

Keep in mind that this is what worked for my particular application, your milage may vary, although the general idea should be the same. Stick the destination path in a session variable on the login form and pull it out and use it for the #redirect on the user_register form.

-mike