Skip to content

Model Object

errorsOn()

errorsOn() — returns array

Available in: model Category: Error Functions

errorsOn() returns an array of all errors associated with a specific property of a model object. You can also filter by a specific error name if needed. This is useful when you need programmatic access to errors rather than just displaying them in the view.

NameTypeRequiredDefaultDescription
propertystringyesSpecify the property name to return errors for here.
namestringnoIf you want to return only errors on the property set with a specific error name you can specify it here.
Example 1 — Basic usage
<cfscript>
user = model("user").findByKey(12);

errors = user.errorsOn("emailAddress");

writeDump(errors);
</cfscript>

Returns an array of error objects associated with the emailAddress property.

Each element typically contains the error message and metadata like name or type.

Example 2 — Filter by error name
<cfscript>
errors = user.errorsOn("emailAddress", "uniqueEmail");

writeDump(errors);
</cfscript>

Returns only errors for emailAddress that have the error name uniqueEmail.

Example 3 — Checking if a property has any errors
<cfscript>
if (arrayLen(user.errorsOn("password")) > 0) {
 writeOutput("Password has errors!");
}
</cfscript>

This is helpful when you need conditional logic based on whether a field has errors.

Example 4 — Iterating over errors
<cfscript>
errors = user.errorsOn("username");

for (var e in errors) {
 writeOutput("Error: " & e.message & "<br>");
}
</cfscript>

Loops through all errors on a property and outputs the messages individually.