The scenario is :

I've implemented a menu using hook_menu and in that page it checks if user have access to creating certain content type (called request) if he/she does have access it will load content creation page using drupal_get_form else it checks if user is not logged in, in this case it loads user_login_block, again with drupal_get_form function, finally if user is logged in and still does not have access to create content type, it shows a message about that.

the problem is : I want user redirect to this same page after login, it redirects to user/uid by default.

This is the code for my page provider function :

Global $user;
$content = "";
if(user_access('create request content')){
module_load_include('inc', 'node', 'node.pages');
$node_form = new stdClass;
$node_form->type = 'request';
$node_form->language = LANGUAGE_NONE;
$form = drupal_get_form("request_node_form", $node_form);
$content .= drupal_render($form);
if($user->uid == 0) {
  $login_form = drupal_get_form('user_login_block');
  $login_form['redirect'] = drupal_get_destination();//What I did to get form redirected, but no chance
  $content = '<p>For better controlling on your project flow consider signing in before submitting your file.</p>';      
  $content .= drupal_render($login_form);
  $content = "Unfortunately only user of role customer can submit a request.report any problem by sending email to --------";
return $content;

I also tried Login Destination but it neither worked.

1 Answer 1


There are several methods to redirect user to specified url after login

You can use Rules

Events: User has logged in.<br/>
Condition: User has role<br/>
Actions: Page redirect<br/><br/>

Another one with drupal api:

   function hook_user_login(&$edit, $account) {   
     $edit['redirect'] = 'yourpath';

if it not worked try to change $GLOBALS['destination'] with

function hook_user_login(&$edit, $account)  {
  $GLOBALS['destination'] = 'yourpath';

Also you can use Login Redirect module

Overview A simple module providing a method to redirect users according to an URL-defined parameter after logging in. Allows redirects toward non-Drupal location.


Lightweight and minimal configuration. No module dependencies!
Allows custom URL parameter name
Filters XSS URL input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.