After this lesson you will be able to:
Note: If you do not have the working documents from the previous lessons, download a copy now.
In this lesson we will introduce the basic web form elements that you might use in your pages. They will not actually do anything until the next lesson.
A web page form is defined by a set of <form>....</form> tags where everything in between includes HTML to code the different text fields, buttons, and drop down menus that are used to store selections from the page viewer. You can also have other HTML code inside the form that serve as labels for your form elements.
As an example, look at the source HTML used for the Writing HTML Alumni page. This page includes several different form elements for inputting text. The page layout is defined by using tables to arrange the form elements. The HTML on that page form includes different input elements that as well as the table tags that define their layout.
The bare bones format for writing a form is:
<form action="[url for server program]" method="GET/POST"> : : (form elements) : </form>
We will talk more in the next lesson about the meaning of the options in the <FORM> tag. For now think of the value for ACTION=... as something that tells the browser the location of a script or program that will process the data sent by the browser via the selections in the form. The two values for METHOD=..., POST or GET define one of two ways the data from the form is sent to the program that will process the data.
Now we will review the different form elements you can use. All of the elements inside the <FORM> tags can send some information about their contents and whether or not they have been activated by the web page viewer. Each element includes a defined "type" plus a unique indentifying name for that element. When the form data is sent to the web server, each element sends its name and its current state or value.
NOTE: For this lesson we have created a simple JavaScript alert message to appear when you try the Submit button. If you had entered any text, or changed any button.menu selection, the Reset button above will revert them all to their initial state.
We will now create a web page form that uses all of these elements. This is going to be an additional feature of our Volcano Web project portion. The purpose of the form is to provide a place for people who are doing their projects to submit their reports. We could use this in several ways; it could send the reports as email to the instructor, it could write the report data to a file on the web server, or it could generate a formatted web page report for the student which they could then print. There are other things we could do with data sent by a web form and this is but one example.
Hopefully now you will see an advantage of using the frames display we created for this area in lesson 26. We will create one new web page that will display the form in the main display area and we will modify the left side frame that contains the menu of choices to add a link for our new page.
<A HREF="proj_report.html"> <font size=+2 face="arial,helvetica">R</font>EPORT...</A><br> a form to submit your report
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head></head> <BODY BGCOLOR=#FFFFCC TEXT=#333333 LINK="#0000CC" VLINK=#FF6666> <h2 align=center>Report Form</h2>
<form method="post">
<table border=0 cellpadding=4 cellspacing=1> <tr> <td colspan=2 bgcolor="#003333"><font size=+3 color=#CCCCCC> <tt><b>student information</b></font></td> </tr> <tr> <td valign=top align=right><tt><b>name</b></td> <td valign=top><input type="text" name="name" size="40"><br> <font size=2 color=#000099>enter your full name</font> </td> </tr> <tr> <td valign=top align=right><tt><b>email</b></td> <td valign=top><input type="text" name="email" size="40"><br> <font size=2 color=#000099>enter an internet contact address</font> </td> </tr> <tr> <td valign=top align=right><tt><b>password</b></td> <td valign=top><input type="password" name="pass" size="20"><br> <font size=2 color=#000099>enter a code to identify you to your instructor</font> </td> </tr>
NOTE: We have created a 2 column cell for the text "student information" followed by three table rows that contain text input form fields. We have put the labels for the field in the first column of each row, right aligned. We also provide brief instructions in small, blue text below each form element.
Note how each form element has a unique name. The third form field is actually a password type to shield the code name the user will type in.
<tr> <td valign=top align=right><tt><b>volcano name</b></td> <td valign=top><input type="text" name="vname" size="40"><br> <font size=2 color=#000099>enter the name of the volcano you researched</font> </td> </tr> <tr> <td valign=top align=right><tt><b>location</b></td> <td valign=top><input type="text" name="vlat" size="10"> latitude<br> <input type="text" name="vlong" size="10"> longitude<br> <font size=2 color=#000099>enter the map coordinates that locate this volcano</font> </td> </tr> <tr> <td valign=top align=right><tt><b>type</b></td> <td valign=top> <select name="vtype"> <option value="select" selected>Select the type...</option> <option value="Hawaiian">Hawaiian</option> <option value="Surtseyan">Surtseyan</option> <option value="Strombolian">Strombolian</option> <option value="Phreato-Plinian">Phreato-Plinian</option> <option value="Plinian">Plinian</option> </select><br> <font size=2 color=#000099>select the volcano type (see <a href="term.html" target="_top">volcano terminology</a>)</font> </td> </tr> <tr> <td valign=top align=right><tt><b>activity</b></td> <td valign=top> <input type="radio" name="active" value="active" checked> active <input type="radio" name="active" value="inactive"> inactive<br> <input type="text" name="vdate" size="40"><br> <font size=2 color=#000099>enter the date of last known eruption, if known</font> </td> </tr> <tr> <td valign=top align=right><tt><b>features</b></td> <td valign=top> <input type="checkbox" name="note1" value="danger risk">danger risk to nearby population<br> <input type="checkbox" name="note2" value="historic eruptions">has erupted in historic time<br> <input type="checkbox" name="note3" value="observed">has been observed in detail<br> <input type="checkbox" name="note4" value="explosive eruptions">explosive eruptions<br> <input type="checkbox" name="note5" value="mild eruptions">mild eruptions<br> <font size=2 color=#000099>check all that apply</font> </td> </tr> <tr> <td valign=top align=right><tt><b>more info</b></td> <td valign=top><textarea name="info" rows="12" cols="40" wrap=virtual> </textarea><br> <font size=2 color=#000099>write any other information that you have learned about this volcano</font> </td> </tr>
NOTE: Be sure to compare the format of radio buttons versus check boxes; each radio button in a set has the same name while all of the check boxes have different names.
<tr> <td colspan=2 bgcolor="#003333"><font size=+3 color=#CCCCCC> <tt><b>sources</b></font></td> </tr> <tr> <td valign=top align=right><tt><b>references</b></td> <td valign=top><input type="text" name="ref1" size="40" value="http://"><br> <input type="text" name="ref2" size="40" value="http://"><br> <input type="text" name="ref3" size="40" value="http://"><br> <font size=2 color=#000099>provide three web site URLs that you used in your research</font> </td> </tr>
<tr> <td colspan=2 bgcolor="#003333"><font size=+3 color=#CCCCCC> <tt><b>send report</b></font></td> </tr> <tr> <td valign=top align=right> </td> <td valign=top> <input type="submit" value="Send in My Report"> <input type="reset" value="Erase Report Form"> </td> </table> </form> </body> </html>
Compare your web pages with this sample of how it should appear. If your pages are different from the sample or the hypertext links do not work correctly, review the text you entered in the text editor.
Review topics for this lesson:
Experiment with writing web page form elements to your own web pages. How would you create a web page that has more than one form on it?
Let's make that web page form do something!
Writing HTML: Lesson 28a: Forming Forms
©1994-1999
Maricopa Center for Learning and Instruction (MCLI)
Maricopa Community Colleges
The 'net connection at MCLI is
Alan Levine
Comments to alan.levine@domail.maricopa.edu
URL: http://www.mcli.dist.maricopa.edu/tut/tut28a.html