function drupal_set_message

Same name and namespace in other branches
  1. 8.9.x core/includes/ \drupal_set_message()

Sets a message to display to the user.

Messages are stored in a session variable and displayed in page.tpl.php via the $messages theme variable.

Example usage:

drupal_set_message(t('An error occurred and processing did not complete.'), 'error');


string $message: (optional) The translated message to be displayed to the user. For consistency with other messages, it should begin with a capital letter and end with a period.

string $type: (optional) The message's type. Defaults to 'status'. These values are supported:

  • 'status'
  • 'warning'
  • 'error'

bool $repeat: (optional) If this is FALSE and the message is already set, then the message won't be repeated. Defaults to TRUE.

Return value

array|null A multidimensional array with keys corresponding to the set message types. The indexed array values of each contain the set messages for that type. Or, if there are no messages set, the function returns NULL.

See also



268 calls to drupal_set_message()
aggregator_aggregator_fetch in modules/aggregator/
Implements hook_aggregator_fetch().
aggregator_aggregator_remove in modules/aggregator/
Implements hook_aggregator_remove().
aggregator_categorize_items_submit in modules/aggregator/
Form submission handler for aggregator_categorize_items().
aggregator_form_category_submit in modules/aggregator/
Form submission handler for aggregator_form_category().
aggregator_form_feed_submit in modules/aggregator/
Form submission handler for aggregator_form_feed().

... See full list


includes/, line 2120


function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) {
    if ($message || $message === '0' || $message === 0) {
        if (!isset($_SESSION['messages'][$type])) {
            $_SESSION['messages'][$type] = array();
        if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
            $_SESSION['messages'][$type][] = $message;
        // Mark this page as being uncacheable.
    // Messages not set when DB connection fails.
    return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL;

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.