What is formenctype Attribute in HTML Form ?
Last Updated :
16 Jun, 2023
The HTML formenctype attribute is used to specify the type of encoding to be used when submitting the form. It defines how the form data should be encoded when it is sent to the server.
It works with the input type “submit” and input type “image“.
The formenctype attribute is used when there are multiple submit buttons inside the form. It is used to override the feature of the enctype attribute of the <form> element.
Syntax:
<element_name formenctype=”application/x-www-form-urlencoded/multipart/form-data/text/plain”>
Basically, there are ways to be used to encode the form data.
- application/x-www-form-urlencoded: It is the default value. It encodes all the characters before being sent to the server. It converts spaces into + symbols and special characters into their hex value.
- multipart/form-data: It is used to encode the file upload controls. This value does not encode any character. we can not upload images and files without using this encoding type.
- text/plain: This value converts spaces into + symbols but special characters are not converted.
Example: in this example, we are using formenctype attribute.
HTML
<!DOCTYPE html>
< html >
< body >
< center >
< h2 style = "color:green" >
GeeksforGeeks
</ h2 >
< p >
< b >
What is formenctype attribute in HTML form?
</ b >
</ p >
< form action = "#" >
< label >First Name:< input type = "text" ></ label >
< br >
< label >last Name:< input type = "text" ></ label >
< br >
< label >Address:< input type = "text" ></ label >
< br >< br >
< input type = "submit"
value = "Submit with default encoding type" >
< button type = "submit"
formenctype = "multipart/form-data" >
Submit as multipart form-data
</ button >
</ form >
</ center >
</ body >
</ html >
|
Output:
![](https://media.geeksforgeeks.org/wp-content/uploads/20211008125758/formenctype.png)
Share your thoughts in the comments
Please Login to comment...