This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26739 - Can we have a builtin method which assembles FormData from the form for XHR2 submission automatically?
Summary: Can we have a builtin method which assembles FormData from the form for XHR2 ...
Status: RESOLVED WORKSFORME
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-05 16:21 UTC by contributor
Modified: 2014-09-19 19:23 UTC (History)
4 users (show)

See Also:


Attachments

Description contributor 2014-09-05 16:21:12 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html
Multipage: http://www.whatwg.org/C#the-form-element
Complete: http://www.whatwg.org/c#the-form-element
Referrer: https://www.google.ca/

Comment:
Can we have a builtin method which assembles FormData from the form for XHR2
submission automatically?

Posted from: 99.237.75.191 by caitpotter88@gmail.com
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36
Comment 1 caitp 2014-09-05 16:23:18 UTC
From #whatwg:

[12:12]  <caitp> would it be a bad thing to have a method of HTMLFormElement which assembles a FormData object automatically? that seems like a nice feature that people have already polyfilled a lot
[12:12]  <jgraham> Certianly not from the point of view of the compiler :)
[12:12]  <caitp> and pretty trivial to implement in a private script, for that matter
[12:13]  * paulohp has quit (Remote host closed the connection)
[12:13]  <jgraham> caitp: Seems like a reasonable idea

--------

This would be a pretty trivial feature to implement. It might even be taken a bit further, like having an "async" content attribute which submits the form via Fetch/XHR rather than navigation, using the specified method/action.

I mean yeah, libraries have been doing this for a while, but it might be a useful thing to let people do by default, and should be easily polyfilled in browsers which support XHR2
Comment 2 Ian 'Hixie' Hickson 2014-09-05 17:04:03 UTC
I thought we had this already. Isn't that what new FormData(myFormElement) does?
Comment 3 caitp 2014-09-05 17:09:33 UTC
Yeah, anne mentioned that. I agree that it's already possible, but there are a few problems with this:

1) nobody would ever expect it to work this way. This is illustrated with the comment I made, "like, suppose you wanted a list of VIN numbers parked in a given parking lot --- the `new FormData()` option is like going to the paper factory and asking them to create a set of papers containing vin numbers from <parking lot>, whereas my suggestion is more like asking the parking lot manager for a list of vin numbers in the lot" --- It just seems semantically backwards as to what is being accomplished, so it doesn't occur to anyone to try this.

2) it doesn't really deal with the extended option I suggested, which I think would be pretty cool and save many lines of code in numerous frameworks (because nobody ever really wants to navigate when submitting a form anymore)

What if `HTMLFormElement#getFormData()` or something were an alias for `new FormData(<form>)`?

What if we did consider an async submission mechanism? There are many lines of code devoted to providing async form submission in numerous libraries, it would be cool if it were possible to make it a builtin.
Comment 4 Anne 2014-09-05 17:13:22 UTC
I'm not convinced this is needed right now. There's bigger fish to fry.
Comment 5 Ian 'Hixie' Hickson 2014-09-08 17:05:48 UTC
(In reply to caitp from comment #3)
> Yeah, anne mentioned that. I agree that it's already possible

Ok. If it's possible, then there's nothing to do here.


> 1) nobody would ever expect it to work this way.

It's how I'd expect it to work...


> This is illustrated with
> the comment I made, "like, suppose you wanted a list of VIN numbers parked
> in a given parking lot --- the `new FormData()` option is like going to the
> paper factory and asking them to create a set of papers containing vin
> numbers from <parking lot>

No it's not. It's like grabbing a piece of paper from the top of the paper pile, and writing down the VIN numbers, instead of first collecting up all the VIN numbers, and telling them to give you a piece of paper with their name on it.


> 2) it doesn't really deal with the extended option I suggested, which I
> think would be pretty cool and save many lines of code in numerous
> frameworks (because nobody ever really wants to navigate when submitting a
> form anymore)

Not sure what you mean here. If you just want to submit the form in the background, use target="" to submit it to an iframe.


> What if `HTMLFormElement#getFormData()` or something were an alias for `new
> FormData(<form>)`?

If it's an alias, then it adds nothing except potential bug surface area, code bloat, and tutorial bloat.


> What if we did consider an async submission mechanism? There are many lines
> of code devoted to providing async form submission in numerous libraries, it
> would be cool if it were possible to make it a builtin.

All submission mechanisms in the specs right now except one (sync XHR, which is heavily deprecated) are async.
Comment 6 Ian 'Hixie' Hickson 2014-09-19 19:23:54 UTC
Closing per comment 5; please reopen if you respond. Thanks.