form encoding


The enctype attribute specifies how the browser encodes and presents the data to the server.


  • application/x-www-form-urlencoded - Default encoding. This encoding cannot be used to upload files to the server.
  • multipart/form-data - This encoding is used to upload files to the server.
  • text/plain - This encoding varies between browsers.

	      	<!DOCTYPE HTML>
			<html>
			<body>
			<form method="post" action="">
			<input name="fave">
			<input name="name">
			<button>Submit</button>
			</form>
			</body>
			</html>
	      

application/x-www-form-urlencoded


If using application/x-www-form-urlencoded encoding


The name and value of each data item is encoded using the same scheme that is used to encode URLs. This is how the encoding is applied to the data in the example form:


fave=Apples&name=FiratName+LastName

Special characters are replaced with their HTML entity counterpart. The name of the data item and the value are separated by the equals sign (=) and data/value tuples are separated by the ampersand character (&).



multipart/form-data


The multipart/form-data encoding tends to be used only for uploading files. Here is how the data from the example form is encoded:


	      	----WebKitFormBoundary2desQWER543CDFGF

	      	Content-Disposition: form-data; name="fave" YourName
	      	------WebKitFormBoundary2desQWER543CDFGF Content-Disposition: form-data; name="name"
	      

text/plain


The mainstream browsers encode data in different ways for this encoding.


Google Chrome encodes data in the same way as for the application/x-www-form-urlencoded scheme, whereas Firefox encodes the data as follows:


	      	fave=xml
			name=studentsempire.com
	      

Each data item is placed on a line, and special characters are not encoded.