Example 7: A simple form

This example is a simple HTML form and a php page to display the form values. A HTML form is just a <form>...</form> that includes input, select, and textarea tags. You can try the form at example-7a.php. To view the source for example-7a.php and example-7b.txt.

The is everything inside the tags:

<form action="action" method="method">
.
.
.
</form>

The action tells the browser where to submit the form, and the method tells it how to submit the form.

Most of a form will be <input> tags. The most common options for input are radio, checkbox, text, and submit. The basic syntax for an input tag is:

<input type="input_type" name="variable_name" value="variable_value">

You can see various options being used in example-7a.php.

Another common tag in a form is the <select> tag. This gives a menu of values for the user to select from. This can be a dropdown menu, or a multiple line menu. The basic syntax for select is:

<select name="variable_name">
<option value="variable_value">option text</option>
.
.
.
</select>

If you obmit the value, the select will return the "option text."

A third common tag is the <textarea>. This is a way to allow users to enter large sections of text. The syntax for this is:

<textarea name="variable_name" cols="number_of_columns" rows="number_of_rows">optional text</textarea>

If you look at the source files [example-7a.php and example-7b.txt], you should have a pretty good idea of how a very basic HTML form works.



© 1996 -- 2005, Noel Schutt
E-mail me at: ski ihatespam at schutt dot org
(hint: delete " ihatespam " , and replace " at " with "@" and " dot " with ".")
Page last updated: 2004.03.31