Opened 12 years ago

Closed 12 years ago

#4259 closed defect (fixed)

[CLA] multiple input values with the same name get clobbered by dojo.formToObject

Reported by: guest Owned by: James Burke
Priority: high Milestone: 1.0
Component: IO Version: 0.9
Keywords: Cc: blaine@…
Blocked By: Blocking:

Description

Consider:

<form name='abc'>
<input name='q' value='a'>
<input name='q' value='b'>
<input name='q' value='c'>
</form>

The browser will send:

q=a&q=b&q=c

formToObject produces:

q=a

because the ret[] array (internal to formToObject) does not take into account the multiple values unless your form has a multiple=true attribute on the select.

DISCUSSION:

I think you want to do what the browser would do in the formToObject code. If I hit submit or I use xhrPost, I would want the back-end code to do the same thing without special-casing.

RELAVANCE:

It turns out that PHP has a notion for array posting that takes multiple values of an input and crushes them into an array if they are formatted as a[]. So to get a list of names for a party you could do something like:

<input type='text' name='name[]'>

and then copy that input tag and duplicate it verbatim (via, say, DHTML) to get an array with several names.

The patch is below and my CLA is on file with dojo.

dojo@…

Attachments (2)

formtoobject.diff.txt (2.4 KB) - added by guest 12 years ago.
diff (cla on file)
formtoobject.diff (1.7 KB) - added by guest 12 years ago.
cla on file

Download all attachments as: .zip

Change History (8)

Changed 12 years ago by guest

Attachment: formtoobject.diff.txt added

diff (cla on file)

comment:1 Changed 12 years ago by James Burke

Milestone: 0.91.0

comment:2 Changed 12 years ago by guest

diff worked on the 2nd post (formtoobject.diff)

Changed 12 years ago by guest

Attachment: formtoobject.diff added

cla on file

comment:3 Changed 12 years ago by tk

Cc: http://trac.dojotoolkit.org/ticket/4259 added

Adding a CC for someone else thats watching for this bug fix.

comment:4 Changed 12 years ago by tk

Cc: blaine@… added; http://trac.dojotoolkit.org/ticket/4259 removed

fixing CC... my bad.

comment:5 Changed 12 years ago by tk

Summary: multiple input values with the same name get clobbered by dojo.formToObject[CLA] multiple input values with the same name get clobbered by dojo.formToObject

verified CLA, just need the patch reviewed and imported.

comment:6 Changed 12 years ago by James Burke

Resolution: fixed
Status: newclosed

(In [10458]) Fixes #4259 and #4330. Fixes for form values with multiple names and for selects with multiple selected options

Note: See TracTickets for help on using tickets.