Cover Image for HTML form Tag
157 views

HTML form Tag

The <form> tag in HTML is used to create a form on a web page. It is used to collect user input and submit it to a server for processing or to perform client-side actions using JavaScript. The <form> element acts as a container for form controls such as input fields, checkboxes, radio buttons, dropdown menus, buttons, and more.

Here’s an example of how the <form> tag is used:

HTML<span role="button" tabindex="0" data-code="<form action="/submit-form" method="POST">        <label for="name">Name:</label>      <input type="text" id="name" name="name" required>        <label for="email">Email:</label>      <input type="email" id="email" name="email" required>        <input type="submit" value="Submit">
<form action="/submit-form" method="POST">
       <label for="name">Name:</label>
       <input type="text" id="name" name="name" required>
       <label for="email">Email:</label>
       <input type="email" id="email" name="email" required>
       <input type="submit" value="Submit">
</form>

In this example, the <form> element contains several form controls: two text input fields for name and email, and a submit button. The action attribute specifies the URL where the form data should be submitted, and the method attribute defines the HTTP method to use (in this case, POST).

When the user submits the form by clicking the submit button, the form data is sent to the specified URL for processing. The form data is typically sent as key-value pairs, where the name attribute of each form control serves as the key and the user-entered value is the value.

The <form> tag supports various attributes and methods for controlling form behavior, such as:

  • action: Specifies the URL where the form data should be submitted.
  • method: Specifies the HTTP method to be used when submitting the form (e.g., GET or POST).
  • enctype: Specifies the encoding type for the form data when using the POST method.
  • target: Specifies the target frame or window where the form response should be displayed.
  • autocomplete: Specifies whether form controls should have autocomplete enabled or disabled.
  • novalidate: Disables HTML5 form validation.
  • onsubmit: Specifies JavaScript code to be executed when the form is submitted.

The form controls within the <form> tag can have various attributes, such as name, id, type, value, required, placeholder, and more, to define their behavior and appearance.

By using JavaScript, you can further enhance form functionality, perform client-side validation, or manipulate form data before submission.

Overall, the <form> tag in HTML is used to create a form on a web page to collect user input and submit it to a server for processing. It serves as a container for form controls and provides attributes and methods to control form behavior and processing.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS