Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Simple & Fast Variable Validation by webmigit
Posted: 18 Aug 02

One of the things developers hate about forms is the extensive validation involved to stop most hackers in their tracks and of course, to help users keep from making simple mistakes.

This is never easy and even less a pleasant experience.. but I have one method I'll share with you to help.

I create an empty variable called fldTrip.. (Field Trip.. If this is not empty, my validation will trip..).

I set this, I do not use a cfparam because I want this variable empty at the beginning of validation.

<CFSET fldTrip="">

Next, I want to check all fields that I do not want to be empty.. these are just standard text fields so its ok for them to have a single character value.

<CFLOOP list="var1,var2,var3" index="i">
  <CFIF Evaluate(I) is "">
   <CFSET fldTrip=ListAppend(fldTrip,"-" & I & "-")>

 <CFIF fldTrip contains "var1">
  <CFSET msgVar1="Message for var1">
 <CFIF fldTrip contains "var2">
  <CFSET msgVar2="Message for var2">
 <CFIF fldTrip contains "var3">
  <CFSET msgVar3="Message for var3">

Now here's the magic part.. to save me a lot of CFIF'ing, I wrote a custom tag to do the dirty work:

--- inerror.cfm ---

<CFPARAM name="attributes.name" default="">

<CFSET localname=Evaluate("Caller." & Attributes.Name)>

<CFIF caller.fldTrip contains attributes.name>
 <BR><FONT size="-1" color="##FF0000"><CFOUTPUT>#Evaluate("caller.msg#attributes.name#")#</FONT></CFOUTPUT>

--- /inerror.cfm ---

Now call the tag next to your text boxes.. so you might have...

<INPUT type="text" name="var1" value=""><CF_inerror name="var1">

And if you've followed all steps, it should work fine..

Tony Hicks
Give a visit to http://www.alfii.com/refdoor.cfm

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close