1

I'm working on a site at the moment where some nodes are hidden behind a login. You can see a list of them, but to view them you need to sign in.

The sign in is done by showing the user login block in a lightbox.

Now the problem I'm having is the submit handler for the form isn't working properly. In my template.php file, it looks like this:

function fisita_redirect_after_login(&$form, &$form_state) {
   drupal_set_message($form['hidden_paper_url']['#value']);
   drupal_goto("http://www.google.com");
   //$form['#redirect'] = $form['hidden_paper_url']['#value'];
   //$form_state['#redirect'] = $form['hidden_paper_url']['#value'];
}

The Drupal set message, works fine, and it is outputting what I want (the URL we're trying to redirect to), but any attempt at changing the page isn't running. Either redirect or drupal_goto.

Does anyone have any clues?

Thanks

2
  • Do you just want to customize the destination that a user is redirected to after logging in ?
    – niksmac
    Commented Jun 6, 2012 at 10:38
  • Yeah, clicking on a node link, changes the value of "hidden_paper_url" to the node's url, so after the login is successful I want the page to redirect to this url. Google's just in there as a test at the moment.
    – SpaceBeers
    Commented Jun 6, 2012 at 10:43

5 Answers 5

4

I had a problem like this and I used this as a workaround to get the page to redirect:

$url = url("node/$nid");
header("Location:$url");
drupal_set_message(t('Message to be displayed in the next page'));
drupal_exit(); 
2
  • 1
    You sir are a hero.
    – SpaceBeers
    Commented Jun 6, 2012 at 11:06
  • 2
    +1...but if you're using Drupal 7 it'd be wise to use drupal_exit() rather than exit(), so Drupal can properly clear up after itself
    – Clive
    Commented Jun 6, 2012 at 11:07
1

I think it's redirect in $form_state not #redirect:

$form_state['redirect'] = 'path/to/page';

1

Dave's answer works, but it just felt wrong, like wasn't "the Drupal way"...

function mymodule_user_login(&$edit, $account) {  
    $GLOBALS['reasons_to_h8_drupal']='this';
}
function mymodule_drupal_goto_alter(&$path, &$options, &$http_response_code){
    if (@$GLOBALS['reasons_to_h8_drupal']=='this'){
        $path = '/first-page-after-login';
    }
}
0

Try this Login Destination

The Login Destination module allows you to customize the destination that a user is redirected to after logging in, registering to the site (7.x), using a one-time login link or logging out (7.x). The destination can be an internal page or an external URL. It is possible to specify certain conditions like referring pages or user roles and make the destination depend upon them. You may use PHP snippets to provide custom conditions and destinations. It is also possible to keep users on the currently visited page after logging in or out.

1
  • Can the destination be set to a form field?
    – SpaceBeers
    Commented Jun 6, 2012 at 11:00
0

1.Are you sure "fisita_redirect_after_login" is working?

2.I had met a similar problem like this, change form redirect or druapl_goto in form_submit not work, it maybe this function is not last change form function, because form['#submit'] is an array.

3
  • 1. Yeah, the set message is showing up so the function's working.
    – SpaceBeers
    Commented Jun 6, 2012 at 10:42
  • so, maybe second possible status ?
    – Rylyn
    Commented Jun 6, 2012 at 10:44
  • I'm not sure I follow point 2. Sorry
    – SpaceBeers
    Commented Jun 6, 2012 at 10:45

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.