Lecture 4
Lecture 4
Forms in HTML
Sure! The `<form>` tag in HTML is used to create an HTML form for user input. It's a container
for form elements, such as input fields, buttons, checkboxes, radio buttons, and more.
```html
</form>
```
- `action`: This attribute specifies the URL (web address) where the form data will be submitted
when the form is submitted. It can be a relative or absolute URL.
- `method`: This attribute specifies the HTTP method to be used when submitting the form data.
The two most common methods are:
- `GET`: The form data is appended to the URL in the form of query parameters. It's suitable for
forms with a small amount of data and when you want users to be able to bookmark or share
the resulting URL.
- `POST`: The form data is sent in the body of the HTTP request. It's suitable for forms with
sensitive data or large amounts of data.
```html
<form action="/submit-form" method="POST">
<label for="username">Username:</label>
<label for="password">Password:</label>
</form>
```
In this example:
- The form will be submitted to `/submit-form` when the user clicks the submit button.
- Two input fields are included: one for the username and one for the password.
- Each input field has a `name` attribute, which is used to identify the data when the form is
submitted.
- The submit button (`<input type="submit">`) is used to send the form data to the server.
When the user fills out this form and clicks the submit button, the data will be sent to the
server according to the specified action and method.