Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Multi-dimensional array form post via ajax

Guest
Dec 21, 2012 Dec 21, 2012

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?

1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2012 Dec 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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 21, 2012 Dec 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 21, 2012 Dec 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="">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2012 Dec 21, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2012 Dec 22, 2012
LATEST

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)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources