I tried in my test site, and the message appears, even using drupal_goto()
. I used the following code.
function code_testing_date_form($form, &$form_state) {
$form['expire'] = array(
'#type' => 'date_select',
'#title' => t('Expire Date'),
'#default_value' => date('Y-m-d H:i:s'),
'#date_format' => 'Y-H:s',
'#date_year_range' => '0:+20',
'#required' => TRUE,
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
'#default_value' => 5,
'#delta' => 10,
'#access' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function code_testing_date_form_submit($form, &$form_state) {
drupal_set_message('You have been redirected.');
drupal_goto('user');
}
What could cause the issue you are seeing could be:
- There is code that clears the content of
$_SESSION['messages']
, used to contain the messages set with drupal_set_message()
.
- There is code that invalidate the current session. In this case, the logged-in user should be logged out.
- You are rendering the form in a template file.
The template file for the page to which the users are redirected doesn't have code to handle the $messages
variable. The default node.tpl.php file contains the following code; if the template doesn't print $messages
, the messages set with drupal_set_message()
will be not seen.
<?php if ($breadcrumb): ?>
<div id="breadcrumb"><?php print $breadcrumb; ?></div>
<?php endif; ?>
<?php print $messages; ?>
<div id="main-wrapper"><div id="main" class="clearfix">
drupal_goto()
right afterdrupal_set_message()
in a test form, but the message was shown in the page where I was redirected.drupal_goto()
should not be used in a form submission handler, but that is not what causes the message not to appear.