HTML
Forms 101 - Hard Code Basics
The Opening
Form Tag
All forms begin with the opening form tag below.
The opening tag and its contents are hidden from view.
All forms will end with the closing form tag </form>.
This tag must be placed at the END of the form.
The following opening form tag is a typical example that points
to the popular cgi form mail handler FormMail located in a cgi-bin
directory in the root web directory.
(This is the opening form tag) <FORM ACTION="http://www.anywhere.com/cgi-bin/form-mail.pl"
METHOD="POST">
All form input fields like check boxes, radio buttons, text
fields, drop down selection lists etc. go here, between
the two form tags.
(This is the closing form tag)
</FORM>
The action tag tells the web browser what to do with
the information that has been gathered in the form. In the code
above, the "Action" attribute directs the information
collected in the form to the forms handling CGI "form-mail.pl"
Located in the cgi-bin directory. This is one of the most popular
cgi's in use. It takes the information submitted by your visitor
in the form and emails it to you in delimited, left justified
format.
The exact location of the cgi-bin directory will be determined
by the rules regulating CGI usage at your ISP. Some ISP's allow
you to set up CGI's in a cgi-bin directory in your own root web
directory. Others restrict your ability to run free lance cgi's
and will have a pre built cgi-bin directory on the web
server. In this case, you will need to get the path to
the cgi-bin directory from your ISP.
The METHOD attribute will almost always be "POST."
The other METHOD is "GET." It limits
the number of characters that can be passed from the form to the
cgi to 8,192 which would work with most forms but, to be sure
and not have to think about it, use the POST method. The documentation
that comes with any given CGI script will tell you which
METHOD to use.
In this case, the form information is being submitted to a CGI
program named "form-mail.pl" in the "cgi-bin"
directory (folder) running in the domain's root web directory
on a web server with the fictional address http://www.anywhere.com.
The CGI program "handles" or processes
the form input information. In this case, it processes and
passes the information collected by the form to you in an
email message.
How to Set Up Forms Using HTML
To
begin this tutorial
Create a new folder named "forms_practice."
Inside the forms_practice folder create an "images"
folder.
Download this image
and save it to the "images" folder inside the
forms_practice folder.
Open a blank HTML file with the default set of HTML document
tags and save it to your forms_practice folder. Name it
"form1.html."
Enter the opening and closing form tags between the
body tags.
Create four spaces between the two form tags.
Please follow the instructions between the two form tags
below.
The word Address shown above to the left of the text
field is the visible text the visitor will see on
their page.
The TYPE="TEXT" code defines the kind of input
field, in this case a text box.
The NAME="address" code makes the word "address"
the identifier text that is returned in front of the information
the visitor entered in that text box. It helps you the recipient
know which field the information came from.
In your email you would see "address: 1426B Oak
Street" if your visitor had entered the address 1426B
Oak Street in the text box.
SIZE="60" indicates the length of the TEXT
box in characters.
You can adjust the SIZE attribute to shorten or
lengthen the TEXT box.
2. The CHECKBOX tag
Netscape
Internet Explorer
Opera
<INPUT TYPE="CHECKBOX" NAME="browser" VALUE="Netscape"
> Netscape
<INPUT TYPE="CHECKBOX" NAME="browser" VALUE="Internet
Explorer"> Internet Explorer <INPUT TYPE="CHECKBOX" NAME="browser"
VALUE="opera" checked> Opera
The TYPE="CHECKBOX" code defines the kind of input
field, in this case a CHECKBOX.
The NAME="browser" code makes the word "browser"
the identifier text that is returned to you in email to the right
of the information the visitor entered in the CHECKBOX. It helps
you the recipient know which field the information came from.
If the visitor checked the "Netscape," check
box the word that follows the VALUE=" " attribute,
in this case "Netscape" would be sent to you
in email by the cgi.
In your email you would typically see "Browser: Netscape"
The word Netscape at the end of the line of code is the
word the user will see on the HTML page, it is just regular, formatted
html text..
Visitors can check multiple check boxes in a group making
more than one selection.
Note the last line where the attribute "checked"
follows "opera." This pre-checks, or preselects
the check box. This is often used as a marketing ploy in the hope
you will overlook the pre-checked box and submit it by
default.
The TYPE="RADIO" code defines the kind of input field,
in this case a RADIO BUTTON. TYPE="RADIO" also controls
the behavior of the set of radio buttons. It allows the user to
check only one radio button in a given set of buttons.
The word "answer" that follows the NAME attribute
is returned with the form information and precedes the information
submitted. You do not have to use the word "answer."
You can use any word you want. Be sure to use a single word, no
spaces allowed.
VALUE="yes" is the information returned by
the form as the users choice if they selected this button.
In your email you would see "answer: yes"
The words yes, no and maybe at the end of the lines of code
are the visible words the user will see on the HTML page. Again,
these are regular html text.
Note the last line where the optional attribute "checked"
follows "maybe." This pre-checks or preselects
the radio button. You do not have to preselect a button.
The TEXTAREA code defines the kind of input field, in this case
a TEXTAREA.
The NAME="comments" makes the word "comments"
the identifier text that is returned in front of the information
the visitor entered in the TEXTAREA. It helps you the recipient
know which field the information came from.
In your email you would see "comments: Thanks, great
web site!" if your visitor had entered the comment "Thanks,
great web site!" in the TEXTAREA.
ROWS="10" COLS="50" defines the dimensions
of the TEXTAREA's width and height. You may adjust these numbers
to get a box the size you want.
ROWS define vertical height
COLS define the width of the TEXTAREA.
WRAP="Physical" tells the TEXTAREA to wrap
the text inside the box when it hits the right side.
6. The SUBMIT and RESET(Clear
Form) tags
These two lines of code go at the bottom of most forms. They make
the Submit and Clear Form buttons appear. They allow
the forms user to either submit the information in the form
or, reset (clear) the form.
<INPUT TYPE="SUBMIT"
VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Clear Form">
INPUT TYPE="SUBMIT" and INPUT TYPE="RESET"
define the kind of buttons these are, in this case the Submit
and Clear Form buttons.
The VALUE="Submit" and VALUE="Clear
Form" code define the text on the buttons. You may change
this text if you wish. For example, you could change VALUE="Clear
Form" to VALUE="Reset" and the viewer would
see a button that said "Reset."
7. How to use an "Active
Image" To Send Form Information To The Server CGI.
You
can refer to any gif image and use it as your customized button
for submitting form information. In the example below, we have used
the button "buy.gif" as an example. The "buy.gif"
image is located in the images folder in the forms_practice
folder you created earlier in this tutorial.
This must always be the second to last form element, placed
afterall your form input elements like check boxes,
text areas, radio buttons etc. and just before the closing
form tag. </form>
The active image code that when clicked on will send the forms
information to the server looks like the code below.