Hi,

I've just finished writing the bestest "friendlist" module for Drupal 6. I have one last thing I need to get sorted out... and it's driving be bananas.
(Yes, I will make it available as soon as possible. Yes, I am aware that there is currently no option for Drupal 6 users).

I define two forms. One of them is at http://www.XXXXX.net/friendlist/del/45/3 where 45 is the user, and 3 is the connection type.
Now... this form might get linked potentially from anywhere in the web site. It doesn't have clear "origins" so to speak. What's worse, you get "access denied" if you land back on it. What I really need, is a neat way to:

1) Get the user to the form
2) Let them submit
3) Redirect to the referring pagee

I *know* I could use "?destination". However, it's not ideal: where do I go if destination is not set? The home page? Do I *have to* require people to set destination? What I really want, is go back to the referring URL that got the user landed on the form.

How do you do that?

Bye!

Merc.

Comments

drawk’s picture

You could use $_SERVER['HTTP_REFERER'] but it isn't perfect. Without knowing the module, it is hard to know the workflow, but wouldn't people be landing on that page via links generated either directly by your module or through a call to one of its exposed helper functions so that you could append the page that the link is generated on as the '?destination'?

mercmobily’s picture

Hi,

I am playing with $_SERVER['HTTP_REFERER'] right now... I can see why you said "it's not perfect"...

My module does generate the links. So, I guess I can -- and should -- use "destination" after all.
However, I am getting lost with Drupal 6.

So, if I am on page A (say /node/6001) and my function generates the link, what do I have to pass to the l() function so that it goes back to /node/6001 once the form is dealt with?

Thank you! This is the very last nagging thing and hte module is done... you know what it's like :-D

(4:00AM)
Merc.

drawk’s picture

I'm still getting up to speed with D6 myself, but I think this should work:

l("linktext", $yourdestinationpath, array('query' => 'destination='.$_GET['q']));
or
l("linktext", $yourdestinationpath, array('query' => drupal_get_destination()));

mercmobily’s picture

Hi,

Alright it works. However, I noticed that BOTH drupal_get_destination and $_GET['q'] have the path BEFORE aliasing. I alias things so that /user/3 becomes /user/merc and it's a bit ugly that drupal_get_destination links to /user/1 !

So I did this:

function me_destination()
return(substr( url($_GET['q']) ,1 ));
}

Is this "allowed"? Why doesn't drupal_get_destination return the aliased path?

Bye!

Merc.

P.S.
The module is complete :-D

drawk’s picture

Glad you got it working! I'll look forward to seeing the module in contrib.

I think you could also do this, might be a little Drupal-ier:

l("linktext", $yourdestinationpath, array('query' => 'destination='.drupal_get_path_alias($_GET['q'])));

mercmobily’s picture

Hi,

Thank you.
I am talking to tbe buddylist2 module maintainer at the moment. It's all great. He likes my rewrite, which really is neat as.We need to see if my code will "become" buddylist2 (after a tiny bit of renaming) or if this will be a brand new module... we'll see!

Merc.