Core Documentation

Here you will find the new official reference manuals. These documents are related to the core of TYPO3 and address the built in functionality of TYPO3. They are designed to provide you with in-depth information.

Old Core Documentation


3.12. Flash messages

Since TYPO3 4.3 there is a generic system to show users that an action was performed successfully, or more importantly, failed. This system is known as “flash messages”. The screenshot below shows the various severity levels of messages that can be emitted. It also shows that flash messages can include a header or not.

The different severity levels are described below:

  1. Notifications are used to show very low severity information. Such information usually is so unimportant that it can be left out, unless running in some kind of debug mode.

  2. Information messages are to give the user some information that might be good to know.

  3. OK messages are to signal a user about a successfully executed action

  4. Warning messages show a user that some action might be dangerous, cause trouble or might have partially failed.

  5. Error messages are to signal failed actions, security issues, errors and the like.

Flash messages API

Creating a flash message is achieved by simply instantiating an object of class t3lib_FlashMessage:

$message = t3lib_div::makeInstance('t3lib_FlashMessage', 'My message text', 'Message Header', // the header is optionalt3lib_FlashMessage::WARNING, // the severity is optional as well and defaults to t3lib_FlashMessage::OKTRUE // optional, whether the message should be stored in the session or only in the t3lib_MessageQueue object (default is FALSE));

The severity is defined by using class constants provided by t3lib_FlashMessage:

  1. t3lib_FlashMessage::NOTICE for notifications

  2. t3lib_FlashMessage::INFO for information messages

  3. t3lib_FlashMessage::OK for success messages

  4. t3lib_FlashMessage::WARNING for warnings

  5. t3lib_FlashMessage::ERROR for errors

The fourth parameter passed to the constructor is a flag that indicates whether the message should be stored in session or not (the default is not). Storage in session should be used if you need the message to be still present after a redirection.

In backend modules you can then make that message appear on top of the module after a page refresh / the rendering of the next page request or render it on your own where ever you want.

This example adds the flash message at the top of modules when rendering the next request:

t3lib_FlashMessageQueue::addMessage($message);

The message is added to the queue and then the template class calls t3lib_FlashMessageQueue::renderFlashMessages() which renders all messages from the queue. Here's how such a message looks like in a module:

By default flash messages are shown atop the content of a module. However, if needed, you can change where the messages are shown by manipulating a module's template and inserting the ###FLASHMESSAGES### marker. Messages will then replace that marker instead of appearing at the top of the module.

It is also possible to render a single message directly, instead of adding it to the queue. This makes it possible to display flash messages absolutely anywhere. Here's how this is achieved:

$message->render();