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”.
<input type="image" value="Search" formenctype="multipart/form-data" />
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 with formenctype attribute:
<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="hidden" name="id" value="123" />
<label for="file">Select File:</label>
<input type="file" id="file" name="file" />
<input type="submit" value="Upload" />
<input type="submit" value="Delete" formaction="/delete.php"
No comments have been made yet.
Please login to leave a comment. Login now