We now have enough information to construct a working form, so we will start off with something fairly basic, then afterwards put together a more complicated form that we can examine in depth. Here is the basic form:
That will submit three variables to someform.php: Name, Password, and Age. Note how form variables are given names using the name attribute - the names you use here will be used in the PHP script that receives the variables. Also notice that the default value of a field can be set using the value attribute, which means that the Name text box will be set to "Jim" by default.
A final key thing you should take note of is that the Age field, which will presumably contain numbers like 18, 34, etc, is the same type as the Name field, which is likely to contain strings like "Bob", "Sarah", etc. HTML does not have any way to say "restrict this field to numbers only", which means users can enter their age as "Elephant" if they wish. Never trust input from users!
And now a more complicated form, using various other types:
There are several pieces of particular importance in there, so you should read through carefully:
maxlength="10" is one of the attributes for the Password element - this can be used in normal text boxes too, and acts to restrict the number of characters that be typed in to the value of maxlength - 10, in the example.
Age is now a drop down list box - note how the name attribute is placed inside the select element, but each individual option element has its own value. The text inside the value attribute is what is submitted to the form handler specified in the form's action attribute - the text after each option and before the next option is the text the user will see.
"selected" is specified as an attribute of one of the option elements, which means that that option will be the default selection of the parent select list.
Life story is a text area element. Note that it has attributes rows and cols to specify the size of the text area, in characters.
All members of a "radio" element group need to have the same "name" attribute. The "name" attribute is used to inform the browser which group each "radio" element is part of so that users can only select one at a time.
All members of a check box element group need to have the same "name" attribute, and that "name" attribute needs brackets [ ] at the end. The reason for the brackets is because they inform PHP that the value may be an array of information - users can select multiple values, and PHP will place them all into an array of the value of the "name" attribute.
checked="checked" is specified as an attribute of one of the check boxes, which means it will be checked by default.
GET is the method attribute for the form, meaning that the information sent through to the handler page (someform.php) will be sent in the location bar of the browser as a normal URL. This will allow you to see how easy it is to change variables in the location bar, and, by entering lots of text into the Story text area element, how easy it is to have too much data for GET to handle.
Take a look at the illustration below to see how the form should look:
Hundreds of books have been published on HTML programming, and if you want to carry on learning more about HTML you will do best to pick up one of them - that is the section on HTML forms pretty much over with.