INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- 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.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site
(Download This Button Today!)
"...Your site is one of the cleanest and BEST forums that I
have seen. I have sent quite a few people your way. Keep up
the good work!!!"
Where in the world do Tek-Tips members come from?
Simple & Fast Variable Validation
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.
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..
Give a visit to http://www.alfii.com/refdoor.cfm
Back to Adobe: ColdFusion FAQ Index
Back to Adobe: ColdFusion Forum
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:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close