User login

How to redirect after a Drupal form by the way you link to the form

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.