An HTML form is simply a collection of HTML elements embedded within a standard Web page.
By adding different types of elements, you can create different form fields, such as text fields, pull-down menus, checkboxes, and so on.
All Web forms start with an opening <form> tag, and end with a closing </form> tag:
<form action="myscript.php"method="post"> < !-- Contents of the form go here --> </form>
The second line of code in this example is an HTML comment -- everything between the <!-- and -->is ignored by the Web browser.
There are two attributes within the opening <form> tag:
Tag | Description |
---|---|
action | tells the Web browser where to send the form data when the user fills out and submits the form. This should either be an absolute URL (such as http://www.example.com/myscript.php) or a relative URL (such as myscript.php, /myscript.php, or../scripts/myscript.php). The script at the specified URL should be capable of accepting and processing the form data; more on this in a moment. |
method | tells the browser how to send the form data. You can use two methods: get is useful for sending small amounts of data and makes it easy for the user to resubmit the form, and post can send much larger amounts of form data. |