HTML Basics

HTML Introduction HTML Basic HTML Comments HTML Tags/Elements HTML Attributes HTML Formatting HTML Block and Inline HTML Charsets HTML Classes HTML Colors HTML Div HTML Headings HTML Id HTML Iframes HTML Images HTML File Paths HTML Tables HTML Layout HTML Lists HTML Links <a> HTML Paragraphs HTML Quotations HTML JavaScript HTML Emojis HTML URL Encode HTML Entities HTML Computercode HTML Symbols HTML Styles

HTML Forms

HTML Forms HTML Form Elements HTML Form Attributes HTML Input Attributes HTML Input Regex HTML Input Form Attributes HTML Input Types

HTML SEO

HTML Head HTML Page Title HTML Responsive HTML Semantics HTML Favicon

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Audio HTML Video

HTML Reference

a abbr acronym address applet area article aside audio b base basefont bdi bdo big blockquote body br button canvas caption center cite code col colgroup data datalist dd del details dfn dialog dir div dl DOCTYPE dt em embed fieldset figcaption figure font footer form frame frameset h1_-_h6 head header hgroup hr html i iframe img input ins kbd label legend li link main map mark menu meta meter nav noframes noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script search section select small source span strike strong style sub summary sup svg table tbody td template textarea tfoot th thead time title tr track tt u ul var video wbr

How HTML Forms Work

HTML forms are used to collect user input on a website. Forms can contain various types of input fields such as text fields, checkboxes, radio buttons, and submit buttons. When a user fills out a form and submits it, the data is sent to the server for processing. This tutorial will teach you how to create a basic form in HTML.

Creating a Form

To create a form in HTML, you need to use the <form> tag. The <form> tag contains all the input fields and buttons that make up the form. Here's an example of a basic form:

<form>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name"><br>
  
  <label for="email">Email:</label>
  <input type="email" id="email" name="email"><br>
  
  <input type="submit" value="Submit">
</form>

In this form, we have input fields for the user's name and email address, as well as a submit button. When the user submits the form, the data will be sent to the server specified in the action attribute of the <form> tag.

Handling Form Data

Once the form is submitted, the data is typically processed by a server-side script (such as PHP or Node.js). The server-side script can access the form data using the $_POST or $_GET superglobals, depending on the HTTP method used to submit the form.

Here's an example of a PHP script that processes the form data from the previous example:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = $_POST["name"];
  $email = $_POST["email"];
  
  echo "Name: " . $name . "<br>";
  echo "Email: " . $email;
}
?>

Conclusion

HTML forms are an essential part of web development, allowing users to interact with websites and submit data. By following this tutorial, you should now have a basic understanding of how HTML forms work and how to create and process form data.