[development] Path Redirect Location Storage

Steve Edwards killshot91 at comcast.net
Tue Mar 24 18:46:46 UTC 2009


I've been working with a UC module that forces the user to either log in or create a new account before being able to purchase a 
product.  The idea is that once the user has logged in or created the account, they will be redirected back to the node being 
purchased (a class registration in this case).  The way the module is trying to do it is by storing the current location in a 
$_SESSION variable, calling drupal_goto(), and in hook_form_alter(), changing the $form['#redirect'] property to the saved 
location.  The problem is, the $_SESSION array gets wiped out at the end of drupal_goto() after the header is sent to the browser, 
so when the portion of hook_form_alter that will set $form['#redirect'] back to the saved location is called, the variable is 
gone, so the user is left at their profile screen instead of being redirected.

I made a modification to pass the current location (before being directed to /user) to drupal_goto() as the $query parameter (see 
drupal.org/node/409134).  That works fine, as long as the user logs in.  However, if the user needs to create a new account, they 
click on the "Create New Account" link (which goes to /user/register), and the destination parameter is lost from the URL.  The 
data is saved to the session table, so I could query the session table with the session ID to get the URL, but seems sort of messy.

So, can anyone give me an idea of the best way to store the URL so that the user can be redirected back to where they came from 
when they are forced to create a new account?

Thanks.

Steve


More information about the development mailing list