enctype (HTML attribute)
Example
In this example, theenctype attribute tells the browser to send form
data unencoded: <form action="address.php" method="get" enctype="text/plain">
<div>
<label for="txtname">Full Name:</label>
<input type="text" name="txtname" id="txtname"/>
</div>
<div>
<label for="txtcontacttel">Contact Tel:</label>
<input type="text" name="txtcontacttel" id="txtcontacttel"/>
</div>
<div>
<input type="submit" name="cmdSubmit" id="cmdSubmit"
value="Send personal details"/>
</div>
</form>
Description
The
enctype attribute’s purpose is to indicate how
form data should be encoded prior to it being sent to
the location defined in the action attribute. By
default, form data is encoded so that spaces are converted to
"+" symbols, and special characters—for example,
apostrophes, percentage and other symbols, and so on—are converted to
their ASCII HEX equivalents.
Value
The default value (which is assumed,
and doesn’t need to be set explicitly) is
"application/x-www-form-urlencoded". It ensures that
all characters are encoded before they’re sent to the server. The other
possible values are "multipart/form-data", which is
required when you’re using forms that have a file upload control (it
ensures that no character conversion takes place, and transfers
form data as a compound MIME document), and
"text/plain", which converts spaces to
"+" symbols, but doesn’t HEX-encode special characters
such as apostrophes.
Compatibility
| IE | 5.5 | Full |
|---|---|---|
| 6.0 | Full | |
| 7.0 | Full | |
| Firefox | 1.0 | Full |
| 1.5 | Full | |
| 2.0 | Full | |
| Safari | 1.3 | Full |
| 2.0 | Full | |
| 3.0 | Full | |
| Opera | 9.2 | Full |
It causes no compatibility issues, and has excellent support across all tested browsers.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

