Back
errorMessageOn()
Returns the error message, if one exists, on the object's property. If multiple error messages exist, the first one is returned. If no error exists, it returns an empty string.
Example 1 — Basic usage
<cfoutput>
#errorMessageOn(objectName="author", property="email")#
</cfoutput>
Displays the first error message for the email property of the author object.
Default wrapper is <span class="error-message">.
Example 2 — Custom wrapper and class
<cfoutput>
#errorMessageOn(
objectName="author",
property="email",
wrapperElement="div",
class="alert alert-danger"
)#
</cfoutput>
Wraps the error in a <div> instead of <span>.
Uses Bootstrap classes for styling.
Example 3 — Prepend or append text
<cfoutput>
#errorMessageOn(
objectName="author",
property="email",
prependText="Error: ",
appendText=" Please fix it."
)#
</cfoutput>
Prepends "Error: " and appends " Please fix it." around the actual error message.
Example 4 — With HTML encoding disabled
<cfoutput>
#errorMessageOn(
objectName="author",
property="email",
encode=false
)#
</cfoutput>
Output is not encoded, which can be useful if you want to include HTML formatting inside the error message itself.
Copied!