Sure, but that's why you loop over the validation types as well.
something like...
valStruct.email = listToArray("null,maxlength,email");
valStruct.email.value = "[EMAIL PROTECTED]";
valid = true;
while(valid) {
valid = true;
for(i = 1; i LT arrayLen(valStruct.email), i = i + 1) {
switch(vType[i]) {
case "null":
valid = isNull(valStruct.email.value);
if (NOT valid)
break;
case "maxlength":
valid = checkLength(valStruct.email.value);
if (NOT valid)
break;
etc...
}
if (NOT valid)
break;
}
}
This is very generally the best form validation routine
I've been able to come up with in CF, at least until the form
collection becomes an object itself. Of course if you are not on
MX...you can't do cfquery's in UDF's, so perhaps the best angle would
be to have each validation type a custom tag...
Wouldn't it be cool though if we could have a loop watched a
particular variable/method for an event? Like if a particular variable
changed...the event is fired which breaks the loop immediately.
--
mailto:[EMAIL PROTECTED]
Friday, June 27, 2003, 7:43:54 PM, you wrote:
JD> That's only checked (as far as I understand it) before each iteration, not
JD> throughout the processing.
JD> In other words setting "theform" equal to "invalid" will not stop processing
JD> immediately - it will finish out the rest of the code in the loop THEN stop.
JD> Jim Davis
>> -----Original Message-----
>> From: Kwang Suh [mailto:[EMAIL PROTECTED]
>> Sent: Friday, June 27, 2003 7:36 PM
>> To: CF-Talk
>> Subject: Re: Smart or Stupid (CFLOOP as a GOTO)
>>
>> Why not use the condition attribute?
>>
>> <cfloop condition="theForm eq valid">
>>
>> ----- Original Message -----
>> From: "Jim Davis" <[EMAIL PROTECTED]>
>> To: "CF-Talk" <[EMAIL PROTECTED]>
>> Sent: Friday, June 27, 2003 5:26 PM
>> Subject: Smart or Stupid (CFLOOP as a GOTO)
>>
>>
>> > This may be a VERY dumb question, but I'm brain fried.
>> >
>> > Okay - so I'm working on a form and I need to validate fields for many
>> > things. Taking "email address" for example I need to validate that it's
>> > been filled in (not zero length), that it's less than 255 characters
>> (the
>> > database limit), that it fits a email format and finally that the email
>> > address isn't already in use.
>> >
>> > What I'd like to be able to do is check through all these validations.
>> The
>> > instant a problem is found I want to stop checking. I would then
>> redisplay
>> > the form and so forth.
>> >
>> > In a custom tag or function I might, when an error is found simply
>> "return"
>> > to the caller with the error information. Since this is a rather small
>> set
>> > and is only the first of many small forms I decided (perhaps wrongly) to
>> > just do the validation at the top of the page.
>> >
>> > To simulate a components ability to return at any point I wrapped the
>> whole
>> > validation block in a CFLOOP from 1 to 1 (1 iteration) - as soon as I
>> hit
>> an
>> > error (and set the error variable) I CFBREAK. Right after the loop I
>> check
>> > the value of the error variable.
>> >
>> > Now that I'm looking at it I'm not sure... is this just the stupidest
>> thing
>> > you're ever heard? Should I take the extra time and create a customized
>> > validation custom tag for each and every form?
>> >
>> > Jim Davis
>> >
>> >
>>
JD>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Host with the leader in ColdFusion hosting.
Voted #1 ColdFusion host by CF Developers.
Offering shared and dedicated hosting options.
www.cfxhosting.com/default.cfm?redirect=10481
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4