The formenctype attribute of a submit button indicates how the form’s data should be encoded for transmission as part of the request payload, and is only valid with a method or formmethod value of “post”.
Syntax:
<button formenctype="application/x-www-form-urlencoded">Submit</button>
<input type="image" value="Search" formenctype="multipart/form-data" />
Elements:
Valid values for formenctype are:
- application/x-www-form-urlencoded; Default. The values of the form’s controls are bundled into ampersand-delimited name/value pairs and submitted as the main content of the request body.
- multipart/form-data; The values of the form’s controls are bundled into individual chunks as part of the request body, with each chunk specifying the element’s name attribute, its mime type and the element’s value. The primary use of this formenctype value is for submitting forms containing file input elements, as the file data is binary-encoded into the request payload and the filename is included alongside the element name.
- text/plain; Rarely used; primarily for passing data unencoded into an email program when the form’s action is a “mailto:” link. Each form element is bundled as an unencoded name/value pair, with one pair per line.
Example
Example with formenctype attribute:
<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="hidden" name="id" value="123" />
<p>
<label for="file">Select File:</label>
<input type="file" id="file" name="file" />
</p>
<p>
<input type="submit" value="Upload" />
or
<input type="submit" value="Delete" formaction="/delete.php"
formenctype="application/x-www-form-urlencoded" />
</p>
</form>
Comments
No comments have been made yet.
Please login to leave a comment. Login now