Magento – Flash / Session Notification Messages

Magento offers an inbuilt flash message class and functions to display success, error, warning and notice messages. You would have seen a message similar to the one below, when submitting the Magento contact form.

Magento Contact Form Submission Success Notification Message

What’s happening there is that the contact form module redirects the visitor back to the Contact Us page by setting a success message in the session class. When the landing page loads, the messages block displays all flash messages that are held in the session.

<?php
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');
?>

In your custom module or anywhere in phtml code, you can add the above code and Magento will display the message on the next page that you load.