Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
What are you doing wrong? You might be complicating something that should be simple. Why are you creating an array in a form?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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="">
Copy link to clipboard
Copied
In ColdFusion a series of checkboxes with the same name is submitted as a list of the checked values. ColdFusion has a number of list functions you can use to process said list.
As my2centz mentioned, if no checkboxes are selected, there will be no form variable at all so you have to decide how to handle that.
Copy link to clipboard
Copied
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)?