Passing the content of an array in a form

2 views
Skip to first unread message

Frédéric

unread,
Dec 20, 2009, 7:10:57 AM12/20/09
to prototype-s...@googlegroups.com
Hi,

I have a little problem. I want to give the content of an array to a new
page through a form. The javascript code is:

this._view.selectedPicts.setAttribute('value', picts);

I retreive the content using mod_python:

fields = util.FieldStorage(req)
selectedPicts = fields['selectedPicts'].split(',')

All works fine under Firefox and Safari/konqueror, but fails under IE8:

Firefox:

fields={'numAdherent': [Field('numAdherent', '20')], 'numEvenement':
[Field('numEvenement', '2')], 'selectedPicts': [Field('selectedPicts',
'P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg')]}

IE8:

fields={'numAdherent': [Field('numAdherent', '20')], 'numEvenement':
[Field('numEvenement', '2')], 'selectedPicts': [Field('selectedPicts',
'[object]')]}

The strange thing is if I log 'picts' before sending the form, it is
correct, even under IE8!

console.debug("OrderingController._submit(): picts=" + picts);

Firefox:

2009-11-0 12:53:55,198::DEBUG::OrderingController._submit():
picts=P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg

IE8:

JOURNAL : 2009-11-0 12:55:10,67::DEBUG::OrderingController._submit():
picts=P4052858.JPG,PB135158.JPG,photo20-08-03_DSC5719net_redimensionner.jpg,_DSC0222.jpg,p1010005.jpg

So, why do I get the wrong string in my form field under IE8? What should I
use instead of just 'picts'?

Thanks,

--
Frédéric

joe t.

unread,
Dec 20, 2009, 7:39:58 PM12/20/09
to Prototype & script.aculo.us
i may be misunderstanding the problem you're describing, but typically
when you submit an array of values with the same field name, you want
to use "[]" on the end of the field name. It's possible IE is
submitting the array in its object form, which the server is seeing as
string "[object]" and sending back untouched. If the fields are in
your HTML, they need an attribute like:
<input ... name="picts[]" />
or if the data is managed by your script, and passed in the
Ajax.Request as part of the parameters option, you still need to wrap
the name into a string:
{ parameters: { "picts[]" : picts ... } }

Sorry if that's on the wrong track.
-joe t.

Frédéric

unread,
Dec 21, 2009, 2:59:00 AM12/21/09
to prototype-s...@googlegroups.com
On lundi 21 décembre 2009, joe t. wrote:

> i may be misunderstanding the problem you're describing, but typically
> when you submit an array of values with the same field name, you want
> to use "[]" on the end of the field name. It's possible IE is
> submitting the array in its object form, which the server is seeing as
> string "[object]" and sending back untouched. If the fields are in
> your HTML, they need an attribute like:
> <input ... name="picts[]" />
> or if the data is managed by your script, and passed in the
> Ajax.Request as part of the parameters option, you still need to wrap
> the name into a string:
> { parameters: { "picts[]" : picts ... } }
>
> Sorry if that's on the wrong track.

Thanks for the explanation.

I was wondering: a better solution is may be to use json? What do you
sthink about?

--
Frédéric

joe t.

unread,
Dec 22, 2009, 12:11:56 AM12/22/09
to Prototype & script.aculo.us
For most typical cases, JSON is easier, and more efficient. For one,
by sending a Content-type header of "application/json" you can send an
array down from the server, and Prototype automatically converts it
into a JSON object you can utilize.

Hope that's helpful. There are much better explanations in the API
documentation, and people here in the group who can articulate it much
better than i.
-joe t.

Frédéric

unread,
Dec 22, 2009, 3:09:21 AM12/22/09
to prototype-s...@googlegroups.com
Le mardi 22 décembre 2009 05:11, joe t. a écrit :

> For most typical cases, JSON is easier, and more efficient. For one,
> by sending a Content-type header of "application/json" you can send an
> array down from the server, and Prototype automatically converts it
> into a JSON object you can utilize.

I'm switching to json, and you're right, it is much easier to handle!

--
Frédéric

Reply all
Reply to author
Forward
0 new messages