Home ›
How to redirect after a Drupal form by the way you link to the formHow to redirect after a Drupal form by the way you link to the form
Submitted by Benjamin Melançon on October 21, 2007 - 6:20am
Update: A Drupal 7 approach.
Redirecting Users After Submitting a Form in Drupal 5
http://drupal.org/node/134000
Agaric's extensive testing laboratory has verified that addding a string in this form works, for node 20:
?destination=node%2F20
When done directly in the browser. The code %2F
is an interpretation of the slash, "/".
The right way:
http://api.drupal.org/api/function/l/5
drupal get current path
http://api.drupal.org/api/function/drupal_get_destination/5
Resolution
A Practical Example of Setting a Form Destination by Your Link to It
<?php global $user; if ($user->uid == 0) {
print l('JOIN', 'user/register', array('class' => 'login'));
?> | <?php
print l('LOGIN', 'user', array('class' => 'login'), drupal_get_destination());
} else {
print l('MY ACCOUNT', 'user/'.$user->uid, array('class' => 'account'));
} ?>
Searched words:
drupal link redirect functionality
which is overriden by destination passed in the url.
drupal destination passed in url
link extension
url fragment
uri query string
drupal login link redirect to current page
drupal l redirect
drupal l destination
Comments
Drupal 6 working
Drupal 6 working example
<?php global $user; if ($user->uid == 0) {
print l('JOIN', 'user/register', array('class' => 'login'));
?> | <?php
print l('LOGIN', 'user/login', array('query' => drupal_get_destination()));
} else {
print l('MY ACCOUNT', 'user/'.$user->uid, array('class' => 'account'));
} ?>
Great!
Works as it should. Thanks
Great Drupal 6 example on how to build links with destination
Thanks for sharing this snippet on building login/register links in the Drupal way to include current path as destination!
Post new comment