Path Redirect Location Storage
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
Quoting Steve Edwards <killshot91@comcast.net>:
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?
?destination=http://sample.com/go/here or #destination='go/here' -- Earnie http://r-feed.com Make a Drupal difference and review core patches. -- http://for-my-kids.com/ -- http://www.4offer.biz/
#destination='go/here' won't work because anything after the hash is not sent to the server. 2009/3/24 Earnie Boyd <earnie@users.sourceforge.net>:
Quoting Steve Edwards <killshot91@comcast.net>:
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?
?destination=http://sample.com/go/here
or
#destination='go/here'
-- Earnie http://r-feed.com Make a Drupal difference and review core patches.
I did exactly that. In my case, I was at /node/add/registration, which is where I wanted to go back to after registration/account creation, and redirected the user to /user, i.e.: drupal_goto('user',drupal_get_destination()); That takes the user to /mysite.com/user?destination=node%2Fadd%2Fregistration%3Fproduct_nid%3D2. If he logs in from there, he is redirected back to mysite.com/node/add/registration. However, if he is a new user and needs to create an account first, he clicks on the "Create New Account" link, which takes him to /user/register (without ?destination). Therefore, when he is done registering, there is no ?destination parameter for the Forms API, so he stays at the user screen. The way the module does the redirect after that is in hook_form_alter(). It looks for the 'node_checkout_redirect' variable on the user screens, and if it sees it, redirects to whatever is stored there. But, as I mentioned, since $_SESSION is wiped out at the end of drupal_goto(), it doesn't know that the redirect needs to happen. That's why I'm looking for an alternate storage location for that redirection location. Steve Earnie Boyd wrote:
Quoting Steve Edwards <killshot91@comcast.net>:
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?
?destination=http://sample.com/go/here
or
#destination='go/here'
-- Earnie http://r-feed.com Make a Drupal difference and review core patches.
Quoting Steve Edwards <killshot91@comcast.net>:
However, if he is a new user and needs to create an account first, he clicks on the "Create New Account" link, which takes him to /user/register (without ?destination). Therefore, when he is done registering, there is no ?destination parameter for the Forms API, so he stays at the user screen.
The way the module does the redirect after that is in hook_form_alter(). It looks for the 'node_checkout_redirect' variable on the user screens, and if it sees it, redirects to whatever is stored there. But, as I mentioned, since $_SESSION is wiped out at the end of drupal_goto(), it doesn't know that the redirect needs to happen. That's why I'm looking for an alternate storage location for that redirection location.
How about the $form_state['storage']? http://drupal.org/node/144132 -- Earnie http://r-feed.com Make a Drupal difference and review core patches. -- http://for-my-kids.com/ -- http://www.4offer.biz/ ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
participants (3)
-
Earnie Boyd -
Lewis Wright -
Steve Edwards