-1

Coming from a form page, I have the following value: test1, test2, test3 .. test50.

To display 1 of them, I can do this

<output> #form.test1# </output>

But I want to display all of them using a loop, how would I do it?

<cfloop index="i" from="1" to="#form.build_found#" >
    <output> #form.testi# </output>
</cfloop>
help
  • 809
  • 5
  • 18
  • 35
  • Yes, accessing dynamically named variables is common task. Here's one thread (short answer: most everything is a scope. use structure notation `scopeName["dynamicVariableName"]` [Getting values from CFLOOP](https://stackoverflow.com/questions/10144133/getting-values-from-cfloop) – SOS Feb 03 '22 at 23:29
  • Here is some light reading for you. https://stackoverflow.com/questions/19683868/display-cfloop-items-in-order-from-form/19684136 – Dan Bracuk Feb 04 '22 at 04:44

1 Answers1

2

That should work:

<cfoutput>
   <cfloop index="i" from="1" to="#form.build_found#" >
        #form["test" & i ]# 
   </cfloop>
</cfoutput>

A few cfml coders might tend to use the evaluate() function. Don't use it, because it opens security holes in code like that.

AndreasRu
  • 1,053
  • 8
  • 14