Home >Web Front-end >HTML Tutorial >In HTML, what does enctype='multipart/form-data' mean?

In HTML, what does enctype='multipart/form-data' mean?

PHPz
PHPzforward
2023-08-22 08:53:221564browse

In HTML, what does enctype=multipart/form-data mean?

Use the enctype attribute to specify how the browser encodes data before sending it to the server. Possible values ​​are -

  • application/x-www-form-urlencoded − This is the standard method used by most forms in simple scenarios.

  • mutlipart/form-data − This is used to upload binary data in a form, such as images, Word files, etc.

Example

Now let’s look at an example −

<!DOCTYPE html>
<html>
<head>
   <title>HTML enctype attribute</title>
   <style>
      form {
         width: 70%;
         margin: 0 auto;
         text-align: center;
      }
      * {
         padding: 2px;
         margin: 5px;
      }
      input[type="button"] {
         border-radius: 10px;
      }
   </style>
</head>
<body>
   <h1>Login</h1>
   <form enctype="multipart/form-data" action="" method="post">
      <fieldset>
         <legend>Enter the login details</legend>
         <label for="EmailSelect">Email Id:
            <input type="email" id="EmailSelect">
            <input type="button" onclick="getUserEmail('abc')" value="abc">
            <input type="button" onclick="getUserEmail('pqr')" value="pqr"><br>
            <input type="button" onclick="login()" value="Login">
         </label>
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var inputEmail = document.getElementById("EmailSelect");
      function getUserEmail(userName) {
         if (userName === 'abc')
            inputEmail.value = 'abc@MNC.com';
         else
            inputEmail.value = 'pqr@MNC.com';
      }
      function login() {
         if (inputEmail.value !== '')
         divDisplay.textContent = 'Successful Login. Hello ' + inputEmail.value.split("@")[0];
         else
         divDisplay.textContent = 'Enter Email Id';
      }
   </script>
</body>
</html>

Log in and display results −

The above is the detailed content of In HTML, what does enctype='multipart/form-data' mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete