1
votes

I'm having an issue when I try to nest pound signs in my ColdFusion code. I keep getting the following error message:

Invalid CFML construct found on line 57 at column 26. ColdFusion was looking at the following text:

#

Here is the code:

<cfloop index="i" from="1" to="12">
    <cfset needRecord.setNeed#i#(#form["need#i#"]#) />
</cfloop>

If I run the loop outside the cfset tag like this:

<cfloop index="i" from="1" to="12">
    needRecord.setNeed#i#(#form["need#i#"]#)
</cfloop>

The code runs and generates what I would like to generate within the cfset tag. Any idea what I'm doing wrong?

Any help would be greatly appreciated.

3

3 Answers

6
votes

Is needRecord a CFC? Here is one way to do it:

<cfinvoke component="#needRecord#" method="setNeed#i#" x="#form['need#i#']#">

Where "x" is the argument name for setNeed. You can also simplify. Something like:

<cfset value = form["need#o#"]>
<cfset evaluate("needRecord.setNeed#i#(value)")>
0
votes

You cannot have pound signs in a cfset unless it is in a string (such as the "need#i#"). Note that for dynamic CFML you can make use of ColdFusion's evaluate() function.

<cfset cfml = "needRecord.setNeed#i#(form[need#i#])" />
<cfset evaluate(cfml) />
-1
votes

I believe that you could re-write it as:

<cfset needRecord.setNeed#i#(form["need#i#"]) />

Pound signs around form[] should not be necessary and that should clear up the nested pound sign issue