11/25/2010

How to show add Success message and add Error message in Magento

This is one of the easiest way to show Either Error message or Success message in magento for one time.If you are thinking to show an error message or success message one time when a page load then it is the best method to use in mganeto.

Show Error Message in frontend

$message = $this->__('Email Id Already Exist.');
Mage::getSingleton('core/session')->addError($message);

Show Success message in frontend

$message = $this->__('You have Register Successfully');
Mage::getSingleton('core/session')->addSuccess($message);

If you wish show Success message or Error Message in Admin html then you need to write your code little bit different

Show Error Message in Admin page

$message = $this->__('1 row has been updated successfully');
Mage::getSingleton('adminhtml/session')->addSuccess($message);

Show Success Message in Admin page

$message = $this->__('Email Id Already Exist.');
Mage::getSingleton(adminhtml/session')->addError($message);

8 comments:

  1. Anonymous12/21/2010

    Thanx for sharing.

    ReplyDelete
  2. Anonymous1/25/2011

    thanx, worked like a charm :)

    ReplyDelete
  3. Anonymous4/01/2011

    Can you say how to show such error or success message in your custom page rather than magento default?


    thanks

    ReplyDelete
  4. If you have make your own module then also you can use this feature to show Error or Success message

    ReplyDelete
  5. Is it possible to fire error and success messages with javascript, after making an ajax call?

    ReplyDelete
  6. This is wonderfull..cheers

    ReplyDelete