Skip to main content
December 21, 2012
Question

Multi-dimensional array form post via ajax

  • December 21, 2012
  • 2 replies
  • 1503 views

I have a form post that is occuring via ajax to a cf script.  One of the variables is a multi-dimensional array.  I can't seem to be able to get access to the values of the array.  When I do a dump on Form, I get keys that look like this:

<CFDUMP var="#FORM#" />

The result(keys):

data[var1], data[var2], data[var3]

########################################

When I try to acess the vars though, all I get is errors:

FORM.data["var1"] .....shows an error

FORM.data.var1 ......shows an error

On the other elements that are not an array from the form post, I can access those values just fine:

FORM.var4 .....displays value

FORM.var5 ..... displays value

What am I doing wrong here?

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
December 22, 2012

Do 2 dumps:

<CFDUMP var="#FORM#" />

<CFDUMP var="#FORM.data#" />

If the first dump doesn't, then the second will tell you what type of variable form.data is. That will in turn tell you how to obtain the values.

So, what type of variable is it? Could you show us a printscreen of the dump(s)?

Inspiring
December 21, 2012

What are you doing wrong?  You might be complicating something that should be simple.  Why are you creating an array in a form? 

December 21, 2012

They are checkboxes that are part of a group.  Coldfusion is not my primary programming languagebut I'm assuming this can be done with CF as well.  In PHP for example, if a group of checkboxes with the same name attribute are submitted via a form, the checkbox name is posted as an array of key/value pairs.  To pull out the indiividual values you can just loop through the array or call the it explicitely. 

Participant
December 21, 2012

Most of the time is your form has checkboxes that are NOT checked nothing is passed. On your form "catcher" you have to param all the possiblities that might help

<cfparam name="form.checkbox1" default="">