Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Tweeted twitter.com/#!/StackDrupal/status/289628580676251648
Source Link
Shawn
  • 425
  • 1
  • 6
  • 16

How can I set a message on the page I am `drupal-goto`ing towards?

I have a page which makes certain verifications and needs to redirect the user in certain cases. In those cases, I want the destination page to show a message, but I can't get it to work. Here is my code:

if ($userNeedsToBeRedirected) {
  drupal_set_message(null, "You've been redirected because ...");
  drupal_goto('destination');
}

The redirection works, but the message doesn't appear. What can I do?

Note: I also tried the following:

if ($userNeedsToBeRedirected) {
  drupal_goto('destination', array(
    'query' => array(
      'message' => "You've been redirected because ..."
    )
  ));
}

and in the destination page:

if (isset($_GET['message'])) {
  drupal_set_message(null, $_GET['message']);
}

but is doesn't work either because (I believe) drupal_set_message is being called too late the the page creation process.