Process for Submitting Form Data
When a submit control is invoked, the user agent MUST prepare a form data set, encode the form data set into a representation, and submit the representation.
Preparing a Form Data Set
To prepare a form data set:
- Let form data set be an empty set.
- Let form be the nearest ancestor of the submit control's value, if it exists.
- If form does not exist, stop preparing a form data set.
- Let inputs be the descendant values of the form's value (in depth-first order) that are described by an
input
specification property.
For each input in inputs:
- Let result be a tuple having name and value components.
- Let name be the value of the input specification property's value, if it is a string. Otherwise, let name be the
name
of the input value, if it exists. Otherwise, repeat the process for each ancestor until name has been resolved. - Let value be a tuple having data and type components.
- For
text
inputs, let data be the value's JSON value (as defined in RFC 4627, Section 2.1) if the value is notnull
orundefined
; otherwise, let data be an empty string. Let type be an empty string. - For
content
inputs, let data and type be the value of thecontent
value'sdata
andtype
properties.
- For
- Let name be the value of the input specification property's value, if it is a string. Otherwise, let name be the
- Append result to form data set.
Encoding a Form Data Set
URL Encoding
When the value of the submit
value's enctype
property is application/x-www-form-urlencoded
, the form data set MUST be encoded as follows:
- Let result be an empty string.
- For each tuple in the form data set:
- Encode the name component according to URL Character Encoding and append to result.
- Append the character '=' (U+003D) to result.
- If the value component's type is an empty string, encode its data component according to URL Character Encoding and append to result; otherwise, continue to the next step.
- If the current tuple is not the last, append the character '&' (U+0026) to result.
- Let the content type of result be
application/x-www-form-urlencoded
.
URL Character Encoding
Encode all characters that are not in the "unreserved" set of RFC 3986, Section 2.3, according to the rules of percent encoding documented in RFC 3986, Sections 2.1 and 2.4.
Multipart Form Encoding
When the value of the submit
value's enctype
property is multipart/form-data
, the form data set MUST be encoded according to the rules of RFC 2388 as follows:
- This section uses the concepts boundary, field, field name, field value, and field content type as defined in RFC 2388, Section 4.1. Each tuple in the form data set is correlated to these concepts as follows:
- The name component correlates to field name. The field name MUST be encoded as UTF-8.
- The data component of the value component correlates to field value.
- The type component of the value component correlates to field content type. If the field content type is an empty string, the resulting part MUST NOT have a Content-Type header specified, and the field value MUST be encoded as UTF-8.
- Let result be an empty sequence of bytes.
- For each tuple in the form data set, encode and append each tuple to result according to the rules above and RFC 2388, Section 4.1.
- Let the content type of result be
multipart/form-data; boundary={boundary}
, where{boundary}
is the value of boundary.
Other Encodings
Other encodings may be supported through extensions to this specification. If the user agent does not understand the submit
value's enctype
, it MUST encode the form data set using Multipart Form Encoding.
Submitting Encoded Data
HTTP and HTTPS
If the method is GET
, DELETE
, or any other method that does not support an entity-body, submit the encoded data as follows:
- Let result be the encoded form data set.
- Let method be the
submit
value'smethod
property value. - Let URL be the submit value's
action
property value. - Let the query component of the URL be result.
- Send an HTTP message, let its method be method, and let its retrieval URL be URL.
If the method is POST
, PUT
, or another method that supports an entity-body, submit the encoded data as follows:
- Let result be the encoded form data set.
- Let method be the
submit
value'smethod
property value. - Let URL be the submit value's
action
property. - Send an HTTP message, let its method be method, let its retrieval URL be URL, let its "Content-Type" header be the content type of result, and let its entity body be result.
Other Schemes
For other schemes, user agents should act in a manner analogous to that defined in HTML, Section 4.10.22.3.