Monday, August 10, 2009

Joomla 1.5 Raising Errors, Notices and Warnings through code

Sometimes it is neccessary to inform an user that incorrect information was entered, like with a login or form validation or sometimes the users needs to be notified what fields needs to be filled in when the form gets loaded.


Making use of Joomla!'s JError class it is possible to display this kind of messages theough the Joomla! framework. To use simply call the JError::raiseError, JError::raiseNotice or JError::raiseWarning methods.


<?php
$msg = 'Error Message';
JError::raiseError(0,$msg);

$msg = 'Notice Message';
JError::raiseNotice(0,$msg);

$msg = 'Warning Message';
JError::raiseWarning(0,$msg);
?>


[update - 11 Feb 2010]
For more go to the following url:
http://docs.joomla.org/Display_error_messages_and_notices