[whatwg] Form Serialization

Garrett Smith dhtmlkitchen at gmail.com
Tue Jan 6 22:02:13 PST 2009

On Tue, Jan 6, 2009 at 9:11 PM, Michael A. Puls II <shadow2531 at gmail.com> wrote:
> On Tue, 06 Jan 2009 17:07:00 -0500, Ian Hickson <ian at hixie.ch> wrote:
>> On Tue, 6 Jan 2009, Michael A. Puls II wrote:
>>> >
>>> > Are browsers actually buggy here?
>>> You probably won't buy it, but I like the idea of using a form as a user
>>> input data gatherer for in-page js-based apps where you do custom things
>>> with the data and often don't actually submit the data anywhere.
>> Oh this is quite common, I'm just not entirely sure that the form data set
>> serialised is a good way of handling that data.
Extremely common.

There are more than one way to handle this, potentially. Submit a FORM
to XHR, for one.

Serialize a form is possible today and it works. It just doesn't work
natively. Well, it does, we just can't get at that serialized value.

> I see. It might be better if there was a getFormData() that returned:
> {
>   "name1" : ["value1", "value2"],
>   "name2" : ["value1", "value2"],
> };

That is the basis for all most form serializers.

> {"image1" : {"file.png" : "data:image/png,base64... }}

Synchronous client-side reads are apparently not going to be a part of
form serialization. What do you do with input type="file"? Sending the
name is pretty useless.


> I'll try to implement a getFormData() in JS how I think it should be while
> trying to follow the spec and provide feedback.


 * If a button submitted the form, it is not included in
serialization. Opera, onsubmit, the event.relatedTarget is the submit
button (nonstandard). The submit button that was clicked should be

 *  input type="image" is not included in the elements collection and
is not included in the serialization in Form.js. The x/y coordinates
don't matter much (you don't need them).

A form serializer should follow the guidelines on successful form controls[1].

In case it isn't obvious, the form controls should not be accessed
directly off the form, e.g. form.controlName (error-prone). Instead
the elements collection should be used, e.g.



More information about the whatwg mailing list