Websnippetz

Get cool snippets on php, css, jQuery, Magento and wordpress

Add success or error message using magento session

Error message

Set error message for front page.


$message = $this->__('Got an error');
Mage::getSingleton('core/session')->addError($message);

Set error message for admin page.


$message = $this->__('Got an error');
Mage::getSingleton('adminhtml/session')->addError($message);

Success message

Set success message for front page.


$message = $this->__('Got an error');
Mage::getSingleton('core/session')->addSuccess($message);

Set success message for admin page.


$message = $this->__('Got an error');
Mage::getSingleton('adminhtml/session')->addSuccess($message);

If you are unable to view the error/success message, add the function session_write_close() after setting message. I got such problem while using with redirect method. Nitroware solved this problem.Now the new snippet will look like below,


$message = $this->__('Got an error');
Mage::getSingleton('adminhtml/session')->addError($message);
session_write_close();

Notice Message

By this way we can show notice message by using addNotice().


$message = $this->__('Please note this modification');
Mage::getSingleton('core/session')->addNotice($message);

karthi s

One thought on “Add success or error message using magento session

  1. Hello Karthik,

    Thanks for the useful article.

    How can I display an error message when the user enters wrong login info (frontend) – when trying to login to the site? (where do I add the error message code)

    Thanks again

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: