HTML Forms

HTML forms are used to collect user input on a web page. They provide a way for users to enter data, make selections, and submit that data to a server for further processing. Here's an example of an HTML form:


html
<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>

    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="4" cols="50"></textarea>

    <input type="submit" value="Submit">
</form>

In the example above, the `<form>` element represents the container for the form. It has two important attributes:


- `action`: Specifies the URL where the form data will be sent when the form is submitted.

- `method`: Specifies the HTTP method to be used when submitting the form, such as "GET" or "POST".


Within the form, we have various input elements:


- `<input type="text">`: Represents a text input field where the user can enter a single line of text.

- `<input type="email">`: Represents an email input field, which ensures that the entered value is a valid email address.

- `<textarea>`: Represents a multi-line text input field, allowing users to enter longer messages or comments.


Each input element has a `name` attribute, which is used to identify the input when the form is submitted. The `id` attribute is used to associate a label with its corresponding input element using the `for` attribute.

The final `<input>` element with `type="submit"` represents the submit button. When clicked, it submits the form data to the URL specified in the `action` attribute using the HTTP method specified in the `method` attribute.

Upon form submission, the data entered by the user is typically sent to a server-side script for processing. The server-side script can handle the data, perform validation, and store it in a database, or perform any other necessary actions.

This is just a basic example of an HTML form. There are many other form elements and attributes available in HTML, such as checkboxes, radio buttons, select dropdowns, and more, which can be used to create more complex forms to suit different requirements.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext