Open In App

How to specify the form-data should be encoded when submitting it to the server in HTML5?

Last Updated : 01 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will specify the form-data should encoding when submitting it to the server by using the enctype attribute in the <form> element in the HTML document. This property specifies the data that will be present in the form that should be encoded when submitting to the server. This property is used to save sensitive user data from a third party. 

Syntax:

<form enctype = "value">

Note: This property can be used only if the method is “POST”

Value: It accepts two value

  • application/x-www-form-urlencoded: It has the default value. It is used to convert all the characters before sent to the server. It encodes the special characters to their hex values.
  • multipart/form-data: It does not encode any plain text and special characters and only converts whitespaces into + symbols.

Example: In this example, we encoded our form-data while submitting it to the server.

HTML




<!DOCTYPE html>
<html>
 
<body style="text-align:center">
    <h2 style="color:green">GeeksforGeeks</h2>
    <b>
          Form-data encoding when submitting it to the server in HTML5
      </b>
    <p></p>
    <form action="#"
          method="post"
          enctype="multipart/form-data">
        First name:
        <input type="text" name="fname"><br />
        <br> Last name:
        <input type="text" name="lname"><br />
        <br> Address:
        <input type="text" name="Address"><br />
        <br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads