tags:

views:

81

answers:

3

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.

+5  A: 

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)")>
CF Jedi Master
Typo in last line of last code block, move the final # inside the ).
CF Jedi Master
you can edit your answer :)
BioBuckyBall
needRecord is a record object. I'm using Reactor.
Ray Buechler
It won't change the execution at all, but with Ray's latter example you don't need the pound signs around the "value" variable: `<cfset evaluate("needRecord.setNeed#i#(value)")/>`
Adam Tuttle
Thanks Adam - even cleaner. Will edit.
CF Jedi Master
Thanks everyone for the assistance. Using evaluate did the trick.
Ray Buechler
A: 

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

Daniel Sellers
Daniel....still getting the same error message but you are right about the pound signs around form!
Ray Buechler
must use cfinvoke or evaluate
Henry
A: 

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) />
Zugwalt
not entirely correct. <cfset x#i# = something> is fine.
Henry