-
<cfif isDefined ( 'form.fieldNames' )>
-
<!---
-
This variable will collect errors.
-
The form display will iterate over
-
the array and display any errors
-
that exist.
-
--->
-
<cfset variables.errors = arrayNew(1) />
-
-
<cftry>
-
<!---
-
Field validation
-
It's extremely annoying to show
-
users one validation error message
-
at a time. These should be collected
-
and displayed en masse.
-
--->
-
<cfif [some field is not valid]>
-
<cfset arrayAppend ( variables.errors, 'Invalid value message' ) />
-
</cfif>
-
<cfif [some other field is not valid]>
-
<cfset arrayAppend ( variables.errors, 'Invalid value message' ) />
-
</cfif>
-
<cfif arrayLen ( variables.errors ) gt 0>
-
<!---
-
The throw will bypass any further
-
processing without the need for an
-
extended cfif block around all of
-
that additional processing.
-
--->
-
<cfthrow type="validation" />
-
</cfif>
-
... start processing ...
-
-
<!---
-
Some processing needs to be isolated
-
for specific error handling. Errors
-
can be rethrown to the primary handler
-
to skip further processing.
-
--->
-
<cftry>
-
... isolated processing ...
-
-
<cfcatch type="any">
-
<cfrethrow />
-
</cfcatch>
-
</cftry>
-
-
... continue processing ...
-
-
<cfcatch type="validation">
-
<!---
-
Errors sent here are already in
-
the errors array and can just be
-
allowed drop to the form view for
-
display.
-
--->
-
</cfcatch>
-
<cfcatch type="any">
-
<!---
-
In the simplest cfcatch scenario,
-
the error message can just be
-
appended to the errors array.
-
--->
-
<cfset arrayAppend ( variables.errors, cfcatch.message ) />
-
</cfcatch>
-
</cftry>
-
</cfif>