Form

In HTML, the <form> element is used to create a form for collecting user input, which is then sent to a server for processing. Forms can contain various types of input elements like text fields, checkboxes, radio buttons, and submit buttons.

Basic Structure of a Form
<form action="submit_page.php" method="POST">
<!-- Text input -->
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required><br><br>
<!-- Email input -->
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required><br><br>
<!-- Submit button -->
<input type="submit" value="Submit">
</form>

Try it yourself

Key Attributes of the <form> Element:

Action:

action: Specifies the URL where the form data will be sent for processing.

<form action="/submit_form">

Method:

method: Defines how the form data is sent to the server. Common values:

  • GET: Appends form data to the URL (visible in the URL).
  • POST: Sends form data as a separate request body (not visible in the URL).
<form method="POST">

Enctype:

enctype: Specifies how form data should be encoded when submitting it to the server (relevant when method="POST"). Common values:

  • application/x-www-form-urlencoded: Default encoding.
  • multipart/form-data: Required when the form includes file uploads.
  • text/plain: Sends data without any encoding.


<form enctype="multipart/form-data">

Target:

target: Specifies where to display the response after submitting the form. Common values:

  • _self: Opens in the same tab (default).
  • _blank: Opens in a new tab or window.
  • _parent, _top: For controlling frames.


<form target="_blank">

Autocomplete:

autocomplete: Enables or disables autocomplete for the form (on or off).

<form autocomplete="off">

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.