Skip to main content
Inspiring
November 13, 2008
Answered

Dynamic variable inside cfloop

  • November 13, 2008
  • 1 reply
  • 458 views
Good day

I have a dynamic form which looks something like this...
<Cfloop from 1 to 6 indes i>
<cfinput type="text" name="description#i#" class="TextBlock">
</cfloop>

When submitting, I want to insert description#i# into a db

At the moment i have this...
<Cfset thedescription = description#i#">
<cfquery name="insertpic" datasource="#application.db#">
INSERT INTO tblpics
(description,)
VALUES ('#thedescription#')
</cfquery>

Its all inisde a loop

How do i set description#i# = somevar?

Please can someone assist?

Regards
Delon
This topic has been closed for replies.
Correct answer Flashdakota
Thank you.
Sorted!

1 reply

Inspiring
November 13, 2008
> How do i set description#i# = somevar?

If you are using method="post", form field values are available in the FORM structure. For method="get" they are available in the URL structure. Since they are structures, you can use array notation to extract reference the dynamic field names: #FORM["baseFieldName"& counterVariable]#

<cfloop index="i" ...>
<cfset description = FORM["description"& i]>
...
</cfloop>

Also, consider using cfqueryparam for all query parameters. Especially when looping.
FlashdakotaAuthorCorrect answer
Inspiring
November 14, 2008
Thank you.
Sorted!