Skip to content

View Helpers

errorMessageOn()

errorMessageOn() — returns string

Available in: controller Category: Error Functions

Returns the error message, if one exists, on the object’s property. If multiple error messages exist, the first one is returned.

NameTypeRequiredDefaultDescription
objectNamestringyes—The variable name of the object to display the error message for.
propertystringyes—The name of the property to display the error message for.
prependTextstringno—String to prepend to the error message.
appendTextstringno—String to append to the error message.
wrapperElementstringnospanHTML element to wrap the error message in.
classstringnoerror-messageCSS class to set on the wrapper element.
encodebooleannotrueUse this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content.
// 1. Display the first error message (if any) on the email property
#errorMessageOn(objectName="user", property="email")#
// -> <span class="error-message">Email is not a valid email address.</span>
// -> (empty string when no error exists on that property)

// 2. Prepend and append custom text around the error message
#errorMessageOn(objectName="user", property="username", prependText="Problem:", appendText="Please try again.")#
// -> <span class="error-message">Problem: Username has already been taken. Please try again.</span>

// 3. Wrap the message in a div with a custom CSS class instead of the default span
#errorMessageOn(objectName="post", property="title", wrapperElement="div", class="field-error")#
// -> <div class="field-error">Title can't be blank.</div>