Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to specify how form-data should be encoded when submitting to server ?

  • Last Updated : 12 May, 2021

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.

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

Example:

HTML






<!DOCTYPE html>
<html>
<body>
   <!--create form to show the implementation of 
    encode type = application/x-www-form-urlencoded  -->
  <form  action="https://www.geeksforgeeks.org/" method="post" 
         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>
  <!--  create form to show the implementation of 
        encode type = multipart/form-data     -->
  <form  action="https://www.geeksforgeeks.org/" method="post" 
         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>
   <!--  create form to show the implementation of 
        encode type = text/plain             -->
  <form  action="https://www.geeksforgeeks.org/" method="post" 
         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




My Personal Notes arrow_drop_up
Recommended Articles
Page :