HTML5: Specify how the form-data should be encoded when submitting it to the server?
Solution:
HTML Code:
<!DOCTYPE html><!-- Opening tag for declaring the document type -->
<html><!-- Opening tag for the root element of the HTML document -->
<head><!-- Opening tag for the document's header section -->
<meta type="utf-8"><!-- Metadata tag (should be charset instead of type) specifying the character encoding of the document -->
<title>Example of HTML enctype attribute with form</title><!-- Title of the HTML document -->
</head><!-- Closing tag for the document's header section -->
<body><!-- Opening tag for the document's body section -->
<form action="https://www.w3resource.com/html-css-exercise/basic/solution/form-enctype-answer-demo.php" method="post" enctype="multipart/form-data"><!-- Opening tag for the form element with attributes specifying the action URL, method, and enctype -->
Name: <input type="text" name="name"><br><!-- Input field for entering a name -->
Address: <input type="text" name="add"><br><!-- Input field for entering an address -->
<input type="submit" value="Submit"><!-- Submit button for submitting the form -->
</form><!-- Closing tag for the form element -->
</body><!-- Closing tag for the document's body section -->
</html><!-- Closing tag for the root element of the HTML document -->
Explanation:
- This HTML code demonstrates a form with the enctype attribute.
- The enctype attribute specifies how the form data should be encoded before it is sent to the server.
- In this case, enctype is set to "multipart/form-data", which is commonly used when the form includes file uploads.
- The form's action attribute specifies the URL to which the form data will be submitted upon submission.
- The method attribute specifies the HTTP method used to submit the form, in this case, POST.
- Inside the form element, there are input fields for entering name and address information.
- Each input field has a name attribute corresponding to the data it represents.
- There is a submit button for submitting the form.
Live Demo:
See the Pen form-enctype-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics