default | grid-3 | grid-2

Post per Page

Coldfusion Form Validation for the Lazy Programmer

I love to program but I don't like to type.  I constantly look for ways to type less but accomplish more.  When I am not using CFWheels I end up having to type a whole lot more.

The other day I came up with this function:

<cfset not_required="billingform,address_2">
<cfloop collection="#form#" item="key">
<cfif not listFindNoCase(not_required,key) and trim(form[key]) is "">
 <cfset variables.e = variables.e & "<li>#ucase(replace(key,'_',' ','all'))# is a required field.</li>">
</cfif>
</cfloop>



The only thing I am not happy about is it doesn't show the error messages in any kind of order, which makes longer form errors look kind of weird, but I don't consider that to be too big of an issue because most of the time a user is only gonna be shown 1 or 2 error messages.

So what do you think?  How could this function be improved upon?

No comments

Error Page Image

Error Page Image

Oooops.... Could not find it!!!

The page you were looking for, could not be found. You may have typed the address incorrectly or you may have used an outdated link.

Go to Homepage