MMv4 KB
 
Can I add error messages to a storefront page?
  Last Edited - 03/29/2012 3:28pm PDT
  Category Path - Developer's Guide > Code Samples
 
question
I have a custom QuickCode Tag that needs to generate an error message in the storefront. Can my custom QuickCode Tag create an error that can be included along with the regular store errors that the {ERRORS} tag displays?

Yes. The list of errors that the {ERRORS} QuickCode Tag displays is based on the variable
$_SESSION[mmid()]['errors']. To add your own error message to the list of errors displayed in the storefront, simply add an entry to this variable.

adding an error
For example, to add an error message that states, "I am an error" to the list of errors displayed on a storefront page, the custom QuickCode Tag would include the following code:

$_SESSION[mmid()]['errors'][] = 'I am an error';

This error will then be displayed, along with any other errors encountered on the page, where the {ERRORS} QuickCode Tag is present in the storefront page's HTML template.

location matters
Any code  that adds an entry to the error variable — or reference to a custom QuickCode Tag that adds an entry to it — must come before the {ERRORS} QuickCode Tag in the HTML Template.

adding success messages
"Success" messages can also be added to the output generated by the {MESSAGE} QuickCode Tag by adding content to this variable:

$_SESSION[mmid()]['notices'][] = 'I am a general message';

Again, any code that adds an entry to this variable must come before the {MESSAGES} QuickCode Tag in the template.





Powered by ModularKB