How to Display Custom Error Messages
Having a Joomla-based web-site, you may need to display a custom error (warning, notice) message. It is very simple and I will tell how you can make so.
In this short tutorial we will deal with the following messages that can be customized:
- Notice message;
- Warning message;
- Error message.
The first thing to know is that all messages are customized by the same method. It would pass number of an error and message for error (warning, notice).
Here is the example:
JError::raiseNotice( 500, Attention! You didn’t register in the system. You will be able to save your order after <a href="index.php?option=com_user&view=register"> registration </a> !’ );
The example creates the following custom notice message for error ‘500’: Attention! You didn’t register in the system. You will be able to save your order after registration.
In fact, you may use this pattern for all custom messages on your site. The only difference for messages is that you should use different classes for notices, warnings and errors. These classes are:
- JError::raiseNotice
- JError::raiseWarning
- JError:raiseError
So, custom warning message will look like:
JError:: raiseWarning( 500, Attention! You didn’t register in the system. You will be able to save your order after <a href="index.php?option=com_user&view=register"> registration </a> !’ );
and custom error message will look like:
JError:: raiseError( 500, Attention! You didn’t register in the system. You will be able to save your order after <a href="index.php?option=com_user&view=register"> registration </a> !’ );
Put this code into the required place and enjoy your result!