View Helpers
errorMessagesFor()
Signature
Section titled “Signature”errorMessagesFor() — returns string
Available in: controller
Category: Error Functions
Description
Section titled “Description”Builds and returns a list (ul tag with a default class of error-messages) containing all the error messages for all the properties of the object.
Returns an empty string if no errors exist.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
objectName | string | yes | — | The variable name of the object to display error messages for. |
class | string | no | error-messages | CSS class to set on the ul element. |
showDuplicates | boolean | no | true | Whether or not to show duplicate error messages. |
encode | boolean | no | true | Encode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead. |
includeAssociations | boolean | no | true |
Examples
Section titled “Examples”Example 1 — Basic usage
<cfoutput>
#errorMessagesFor(objectName="author")#
</cfoutput>
Generates a <ul class="error-messages"> containing all errors for the author object.
Default behavior includes all associated object errors.
Example 2 — Custom CSS class
<cfoutput>
#errorMessagesFor(objectName="author", class="alert alert-danger")#
</cfoutput>
Uses a custom CSS class for styling (e.g., Bootstrap alerts).
Example 3 — Exclude duplicate errors
<cfoutput>
#errorMessagesFor(objectName="author", showDuplicates=false)#
</cfoutput>
Prevents duplicate messages from appearing multiple times in the list.
Example 4 — Include or exclude associated objects
<cfoutput>
<!--- Only show errors on this object, not on associated objects --->
#errorMessagesFor(objectName="author", includeAssociations=false)#
</cfoutput>
Useful if you want to display errors for the main object separately from associated objects (like a nested profile or address).
Example 5 — HTML encoding disabled
<cfoutput>
#errorMessagesFor(objectName="author", encode=false)#
</cfoutput>
Errors are output as-is, allowing embedded HTML in the messages (use with caution).