Flash Notification Messages in Magento



In this tutorial I will explain how to set flash notification messages in Magento. Flash message class and functions to display success, error, warning and notice message is inbuilt in Magento. For example when you submit the contact form and an error occurred below message will display.

error notification
Error message notification

Now when you try again and successfully submitted then following message will display.

Success message notification
Success message notification

The contact form module redirects the visitor back to the Contact Us form page after setting flash messages on success or failure.  So when the page loads the message block displays all the flash messages.

You can add below code to set flash messages in your custom module or anywhere in phtml file and these message will display on the next page load.

Mage::getSingleton('core/session')->addSuccess('Success Message');
Mage::getSingleton('core/session')->addError('Error Message');
Mage::getSingleton('core/session')->addWarning('Warning Message');
Mage::getSingleton('core/session')->addNotice('Notice Message');

I hope this tutorial will help you to add custom flash notification message in Magento.