[whatwg] Adding FormData support to <form>

The FormData object [1] is a great way to allow multipart/form-data
encoded content to be submitted using XMLHttpRequest. It would be
great if it was possible to get a FormData object representing the
data contained in a <form>. This in order to allow normal HTML forms
being used, but using XMLHttpRequest to submit the form data in order
to allow AJAX to be used.

So I suggest we add a method like

interface HTMLFormElement : HTMLElement {
  ...
  FormData getFormData();
  ...
};

The reason this is a function rather than a read-only attribute is to
allow the return FormData to be further modified. I.e. the following
should be allowed:

fd = myFormElement.getFormData();
fd.append("foo", "bar");
xhr.send(fd);

If it was a property I would be worried about people expecting the
following to work:
myFormElement.formData.append("foo", "bar");
xhr.send(myFormElement.formData);

However I don't think there is a good way to make the above work. Thus
my suggestion to use a function instead. I'm writing a prototype
implementation over in [2]

[1] http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=546528

/ Jonas

Received on Wednesday, 17 February 2010 15:15:25 UTC