Skip to main content
March 22, 2012
Question

Cannot loop over struct formfields

  • March 22, 2012
  • 1 reply
  • 961 views

This appears in my dump var:

struct

ACTIONupdateRecordsListings

FIELDNAMESITEMORDER[],ACTION

ITEMORDER[]558,559,536,478,469,468,466,465,464,397,191,11,175

I cannot get it to work to loop over the itemorders and output them. I know it's simple but cannot get it to work.

Here's my code:

<cfloop index="i" from="1" to="#ArrayLen(form)#">
<cfoutput>
  #form.itemorder#

</cfoutput>
</cfloop>

Thank you very much in forward.

This topic has been closed for replies.

1 reply

Inspiring
March 22, 2012

#ArrayLen(form)#">

FORM is a structure, not an array.

#form.itemorder#

Adding square brackets to multiple form field names does not create an array. It just creates a single field literally named "ITEMORDER[]". The value of the field is a comma separated string. To access the value you need to use associative array notation (due to the special characters in the field name ie "[]"). 

         <cfset theCSVList = FORM["itemorder[]"]>

Once you have the value you can cfloop through it as a "list". You could also convert it to an array explicitly and use <cfloop array="...">

March 22, 2012

Thanx Search for this insight.

BKBK
Community Expert
Community Expert
April 1, 2012

If itemorder is an array, then this should work:

<cfloop index="i" from="1" to="#ArrayLen(itemorder)#">
<cfoutput>
  #itemorder#<br>

</cfoutput>
</cfloop>