Saturday, April 02, 2005

Coldfusion Error Checking

Question: I am trying to do some error checking on a login form.

<cfif FORM.username IS "">
<cfset errText = "You forgot to enter a username.">

Unfortunately, errText gets defined every time I run the script whether the username field is empty or not.

Is there another way to check for an empty string?

Answer: I prefer to use the Len() function.

<cfif Not Len(form.username)>
<cfset errText = "Error message here." />


Post a Comment

<< Home