Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Encoding #128

Merged
merged 1 commit into from
Jan 28, 2021
Merged

Form Encoding #128

merged 1 commit into from
Jan 28, 2021

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Jan 22, 2021

Closes #76

According to the HTML Specification for Form Submission Encoding,
there are three possible values:

Encoding declarations on <form method="get"> elements are
ignored
.

This commit re-structures the FetchRequest constructor, and moves the
FormData to URL parameter encoding process out to the FormSubmission
itself, since the HTMLFormElement knows about its enctype and the
submitter its formenctype.

@seanpdoyle seanpdoyle force-pushed the formenctype branch 6 times, most recently from 375ab5d to 40c6455 Compare January 22, 2021 17:04
src/tests/server.ts Outdated Show resolved Hide resolved
src/core/drive/form_submission.ts Outdated Show resolved Hide resolved
src/core/drive/form_submission.ts Outdated Show resolved Hide resolved
src/core/drive/form_submission.ts Outdated Show resolved Hide resolved
src/core/drive/form_submission.ts Outdated Show resolved Hide resolved
src/core/drive/form_submission.ts Show resolved Hide resolved
src/core/drive/form_submission.ts Outdated Show resolved Hide resolved
Closes hotwired#76

According to the HTML Specification for [Form Submission Encoding][],
there are three possible values:

* [application/x-www-form-urlencoded][] (the default value)
* [multipart/form-data][]
* [text/plain][]

[Encoding declarations on `<form method="get">` elements are
ignored][get-ignored].

This commit re-structures the `FetchRequest` constructor, and moves the
FormData to URL parameter encoding process _out_ to the `FormSubmission`
itself, since the `HTMLFormElement` knows about its [enctype][] and the
submitter its [formenctype][].

We don't need to declare the `Content-Type` header, since `fetch` is
capable of inferring that based on whether the body is a `FormData`
instance of an instance of `URLSearchParams`.

[Form Submission Encoding]: https://www.w3.org/TR/html52/sec-forms.html#selecting-a-form-submission-encoding
[application/x-www-form-urlencoded]: https://www.w3.org/TR/html52/sec-forms.html#selecting-a-form-submission-encoding
[multipart/form-data]: https://www.w3.org/TR/html52/sec-forms.html#multipart-form-data
[text/plain]: https://www.w3.org/TR/html52/sec-forms.html#plain-text-form-data
[enctype]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype
[formenctype]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formenctype
[get-ignored]: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#submitting_forms_and_uploading_files
@sstephenson sstephenson merged commit dddeb87 into hotwired:main Jan 28, 2021
@seanpdoyle seanpdoyle deleted the formenctype branch January 28, 2021 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support <form enctype>
3 participants