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
Release: 2023-08-22 08:53:22
forward
1624 people have browsed it

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>
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template