Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error while CFLOOPING 1

Status
Not open for further replies.

Extras

Technical User
Nov 16, 2001
232
US
I am trying to CFLOOP across a bunch of CFIFs but am getting a syntax error. I am getting the following Error message:

Invalid CFML construct found on line 144 at column 33.
ColdFusion was looking at the following text:
#


I am trying to CFLOOP across a CFIF for the various form fields during some server-side validation. The problem area is when I try to use the expression:
(Len(Trim(form.GSub_FName#GiftNum#)) EQ 0)



<!--- THIS STARTS THE LOOP TO CHECK --->
<cfloop index=&quot;GiftNum&quot; list=&quot;1,2,3&quot;>
<!--- THIS CHECKS TO SEE IF EITHER FIRST NAME OR SECOND NAME HAS BEEN FILLED, AND THEREFORE GIFT SUB1 IS INTENDED --->
<CFIF (Len(Trim(form.GSub_FName#GiftNum#)) EQ 0) OR (Len(Trim(form.GSub_LName#GiftNum#)) EQ 0)>
.
.
.
.
.
</CFIF>

 

The only way (that I know of), that ColdFusion can evaluate the value of a dynamic variable is to do the following:

<cfif (len(trim(evaluate(&quot;form.GSub_FName&quot; & GiftNum))) EQ 0) OR (len(trim(evaluate(&quot;form.GSub_LName&quot; & GiftNum))) EQ 0)>

I believe the evaluate() function has some performance drawbacks if used extensively. If you ever had the need to reference a dynamic variable name more than once per request, I would define a temporary variable to hold the value:

<cfset variables.fName_1 = evaluate(&quot;form.GSub_FName&quot; & 1)>

Hope that makes sense.
 
The FORM scope is a structure, so it can be treated as such:
Code:
<CFIF (Len(Trim(FORM[&quot;GSub_FName&quot; & GiftNum])) EQ 0) OR (Len(Trim(FORM[&quot;GSub_LName&quot; & GiftNum])) EQ 0)>
-Tek
 
FWIW- Tek's method will be much faster than evaluate... and usually much more maintanable in the long run. I'd definitely use it wherever possible.
-Carl
 
Sorry for the delayed response. I was out of town. Very much appreciate your follow up and have implemented it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top