How the Browser Formats Form Submissions
When a web page form is submitted, the form data is sent somewhere. Generally, it's submitted to software on the server to handle the data.
For forms with data composed of more than a couple hundred characters, the submission method is almost always method="POST"
.
(The reason is that the number of characters to send method="GET"
is limited to 257 or 1024 characters depending on the browser and on the server where the data is sent to.)
To submit the data method="POST"
, the form encodes and/or formats the data in one of three ways before sending it to the form-handling software on the server. The three ways are listed further below along with an example of the form field and the submitted data.
The form fields for the example submitted data are name="one_line" and name="message", both containing text:
<input name="one_line" value="ONE LINE"> <textarea name="message">HELLO THERE</textarea>
The way the form knows how to encode/enctype
attribute in the form
tag.
Here are the three encoding types with an example form tag and the encoded/
-
application/x-www-form-urlencoded
(This is the default the browser uses whenever the form tag has noenctype
attribute.)Spaces are converted to "+" characters. Other special characters are converted to HEX values.
Example form tag:
<form enctype="application/x-www-form-urlencoded" method="post" action="software.php">
Example submission:
one_line=ONE+LINE&message=HELLO%0D%0ATHERE
-
multipart/form-data
No characters are encoded. The submission data is formatted in multiple parts that are separated with a boundary composed of a special sequence of characters.
Example form tag:
<form enctype="multipart/form-data" method="post" action="software.php">
Example submission:
------WebKitFormBoundaryOQ1HD4YrjOZSIQEd Content-Disposition: form-data; name="one_line" ONE LINE ------WebKitFormBoundaryOQ1HD4YrjOZSIQEd Content-Disposition: form-data; name="message" HELLO THERE ------WebKitFormBoundaryOQ1HD4YrjOZSIQEd--
-
text/plain
Spaces may be converted to "+" characters. The format begins a new line for each form field name. This is followed by a "=" character and then the field value. The next form field name begins another line.
Example form tag:
<form enctype="text/plain" method="post" action="software.php">
Example submission:
one_line=ONE+LINE message=HELLO THERE
For most form handling software, the default enctype="application/x-www-form-urlencoded"
will work fine. Unless the form will have a file upload field.
If the form has a file upload field, enctype="multipart/form-data"
is required. Most form handling software can work with this enctype, also, whether or not the form has a file upload field.
The enctype="text/plain"
is a special type that might or might not be recognized by your software.
When you don't know what type of encoding/enctype="multipart/form-data"
. It works for most applications.
When the form submit button is clicked, the form data is encoded/enctype
attribute of the form tag, then submitted to software. The software determines what the encoding/
Will Bontrager