HTML forms allow the user fill in data, which can then be sent
to the server. Code on the server will then receive this data, and
do something, hopefully useful, with the data.
This topic is discussed in Chapter 11 of your text.
HTML Forms.
Enclosed in a <form>, </form> pair.
Contains input (and some other) tags which are displayed as
input items on the screen.
The form tag has an action attribute which is a URL
to which the data is sent.
It also specifies a transmission method.
method="get"
This is the way normal pages are requested.
Data from the page is added as a query to the end of the URL.
Should be used when the script stores information on the server.
The request can therefore be book-marked.
This is the default.
method="post"
The data are sent in the body of the HTTP request, so the values
do not appear in the URL.
Cannot generally be book-marked.
Forms may be
Static HTML running a separate action script.
Generated by one action script and processed by another.
Generated by an script which also processes the submitted form.
The action URL
May be any valid URL, though a static one doesn't make much sense.
Very common to have the same script both
generate the form and process it.
If the action attribute is omitted from the form tag, this is
exactly what happens: The browser uses the page URL as the action.
Collecting values.
Data from forms appears as key-value pairs.
They appear to PHP in arrays
$_GET for data from get requests.
$_POST for data from get requests.
$_REQUEST for data from either.
Use the isset to see if a value has been set by the form.
Input tags
Most data-collecting tags are input tags, with various
type attributes.
Common attributes.
type tells what sort of entry is drawn.
name identifies the data when sent to the server.
value gives a default, or sometimes only, value to
the item.
Non-closed tag.
Various types of input tag.
type="text": a fill-in box. size= estimates the character
size.
type="checkbox": submits the value, or a 1, if checked. Nothing
if not.
type="radio": radio buttons. Create several with the same
name, and only allow user to check one.
type="hidden": Nothing is displayed, but the name and value
are sent when the form is submitted. <input type="hidden" name="id" value="1948295">
type="submit": Submits the form. Button displays the
value.