HTML form provides three methods of encoding.
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
1.application/x-www-form-urlencoded: This is the default method that is applied if nothing is specified. In this method spaces are converted to the ‘+‘ symbol and special characters are converted to ASCII HEX value, and all other characters remain the same.
Example:
HTML
<!DOCTYPE html>
< html >
< body >
enctype = "application/x-www-form-urlencoded" >
< label for = "fname" >First name:</ label >
< input type = "text" id = "fname" name = "fname" >
< br >< br >
< label for = "lname" >Last name:</ label >
< input type = "text" id = "lname" name = "lname" >
< br >< br >
< input type = "submit" value = "Submit" >
</ form >
</ body >
</ html >
|
Output:
- Accepting form data from the user.

- Accepted the user data on the server.

output
2.multipart/form-data: In this, no characters are encoded. This value is required when a form has a file to upload.
Example:
HTML
<!DOCTYPE html>
< html >
< body >
< h2 >Welcome To GFG</ h2 >
enctype = "multipart/form-data" >
< label for = "fname" >First name:</ label >
< input type = "text" id = "fname" name = "fname" >
< br >< br >
< label for = "lname" >Last name:</ label >
< input type = "text" id = "lname" name = "lname" >
< br >< br >
< input type = "submit" value = "Submit" >
</ body >
</ html >
|
Output:
- Accepting form data from the user.

- Accepted the user data on the server.

3.text/plain: In this, spaces are converted to the ‘+‘ symbol, but no other characters are encoded.
Example:
HTML
<!DOCTYPE html>
< html >
< body >
enctype = "text/plain" >
< label for = "fname" >First name:</ label >
< input type = "text" id = "fname" name = "fname" >
< br >< br >
< label for = "lname" >Last name:</ label >
< input type = "text" id = "lname" name = "lname" >
< br >< br >
< input type = "submit" value = "Submit" >
</ body >
</ html >
|
Output:
- Accepting form data from the user.:

- Accepted the user data on the server.

output
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
12 May, 2021
Like Article
Save Article