HTML Frames and Forms | ||
Computing Education Programmes | ||
Date: | July, 1997 | |
Author: | Ise Henin | |
Last Revision: | September,1998 | |
Revised by: | Laura Proctor |
What are frames and forms?
Frames in HTML
- Basic Frame Structure
- Providing no-Frame Options
- Creating your own Frames
- Naming and Linking Frames
- Problems, Hints and References
Forms in HTML
What are frames and forms? |
Frames - Structured layouts
Forms - Getting feedback |
Section Outline |
Course Outline |
Next Topic |
Frames divide the web browser window into sections that are filled by different documents. Tables (see HTML Publishing Intermediate - Tables) are also used to arrange text and graphics in the browser window. However, frames allow each area of the window to scroll separately. Some typical uses of frames are:The next part of the workshop will show you the file structure of a simple frames-enhanced document and alternative text for browsers that cannot open frames. You will create a web document that uses two frames, then practice changing the size of the frames, add a third frame, and look at some examples. Finally, we will point out some pitfalls and problems to avoid.
- A page with two frames might be used to display navigational buttons (possibly a table of contents) on one side of the window while another frame in the same window contains the body of the document.
- A frame at the top of the window might contain a title or logo which remains on the screen while the content of a document is presented in a frame below it. The lower frame can be scrolled independently of the top title frame.
- Two frames might be used to keep a set of instructions or questions permanently in the browser window, while a student scrolls through a quiz or exercise in a second frame.
Section Outline |
Course Outline |
Next Topic |
Forms add interactivity to web pages by allowing the reader to provide information by filling out a "form" in a browser window. Electronic mail links are also used to allow readers to communicate with you. If you only want some simple information, email links are the simplest method. Forms are better for collecting highly structured information. [See the HTML Publishing Intermediate workshop for more details on email links.]A form may include:
- Areas for the reader to enter text
- Radio buttons, check boxes or option lists for the reader to choose from a set of alternatives
HTML tags are used to define the reader input areas of the form. A special tag is used to display a submit button which the reader will click to submit their responses.
The action taken a form is submitted depends on what facilities (CGI scripts) are available on your web server. For example, Yahoo! (and other search engines) uses a form to allow readers to enter keywords. When the form is submitted (you click the search button), a script on their server searches their database of web pages and sends a list of those which match your keywords back to your browser as a new web page.
At the present time, two CGI scripts are available on the central UVic web server. One script (ShowVars) is intended only for testing purposes and simply redisplays the values entered by the reader in your browser window. The second (FormMail) sends the responses entered by a reader to you (the author) by email. New scripts can only be added in consultation with the UVic web server maintainer (webster@uvic.ca).
The last section of the workshop will introduce typical uses of forms for obtaining feedback from a web page.
You will create a simple form and practice submitting and testing it. Some methods for tailoring the output from the FormMail script for various purposes will be introduced.
Frames in HTML |
Basic Frame Structure
Providing no-Frame Options Creating your own Frames Naming and Linking Frames Problems, Hints and References |
Section Outline |
Course Outline |
Next Topic |
Frames are built by adding a number of <FRAME> tags within the <FRAMESET> and </FRAMESET> tags. If there are two <FRAME> tags the browser window will be divided into two sections, if there are four, the window will be divided into four sections. You can divide the browser window into columns or rows, or a combination of both. Remember, since most people still have rather small screens, it is not wise to use more than two or three frames in a document.The Recipe Book is an example of using frames to create an electronic "book".
Beginning with a simpler example, the following tags are required to create a web page with two frames.
<FRAMESET> <FRAME NAME="Top" SRC="try1top.htm"> <FRAME NAME="Main" SRC="try1main.htm"> </FRAMESET>Click here to see what this example looks like. The example will be displayed in a new browser window. Close the new window when you have finished looking a the example.
Skip Practice |
try1doc.htm try1top.htm try1main.htm try1text.htm
Section Outline |
Course Outline |
Next Topic |
Since there are many browsers that cannot process frames, you should always provide alternate text for these browsers. You use the <NOFRAMES> and </NOFRAMES> tags to mark the beginning and end of the alternative text.An example of tags used to provide alternate text to all browsers which do not process frames:
<NOFRAMES> <BODY> Sorry, your browser doesn't appear to support frames. <P> Please access the <a href="try1text.htm">text-only</a> version of this document. </BODY> </NOFRAMES>The web browsers WinWeb (Windows) and MacWeb (Macintosh) do not support HTML frames. That is, they are not frames-capable. If you use one of these browsers to open a page which does not have a NOFRAME element , you will see nothing in the browser window. The next classroom exercise will guide you through the example documents with one of these browsers.
In lynx, the following screen was displayed for the recipe example. the names of the frames were clickable. If you go to the table of contents (toc), then the contents of the document are fully accessible. Therefore, careful design will allow exactly the same files to be used for both frames and non-frames versions of this particular document.
FRAME: logo FRAME: toc FRAME: main No Frame Option A No-Frame version of this page can accessed at: recipe-text.html
Skip Practice |
Section Outline |
Course Outline |
Next Topic |
You can control the relative sizes and placement of frames through setting the ROWS and COLS attributes on the <FRAMESET> tag.
- ROWS
- Specify the height of each horizontal frame as a percentage of the whole window. For example: <FRAMESET ROWS="10%,50%,40%">
would create three horizontal frames like that shown below.
Top frame is 10% of window Middle frame is 50%
of
the window
Lower frame is 40% of
the window
- COLS
- Specify the width of each vertical frame as a percentage of the whole window. For example: <FRAMESET COLS="10%,50%,40%">
would create three vertical frames like that shown below.
Left Frame is 10% of the window Middle Frame is 50% of the window Right Frame is 40% of the window The examples given above assume that the <FRAMESET> element contains three <FRAME> tags. If you wish one of the (vertical or horizontal) frames to be further divided, you use another <FRAMESET> element rather than a <FRAME> element to define its content.
The following example of mixing rows and columns is illustrated below.
<FRAMESET ROWS="10%,50%,40%"> <FRAME NAME="Top" SRC="top.htm"> <FRAMESET COLS="50%,50%"> <FRAME NAME="Left" SRC="left.htm"> <FRAME NAME="right" SRC="right.htm"> </FRAMESET> <FRAME NAME="Bottom" SRC="bottom.htm"> </FRAMESET>
Top frame is 10% of window Middle left frame is 50%
of
the window
Middle right frame is 50%
of
the window
Lower frame is 40% of
the window
Skip Practice |
Table of Contents
Section 1 Section 2 Section 3 |
Presentation title and author |
Title Page
This is the main text of the document which can be scrolled independently of the other windows. The text displayed in this window will change when a link in the Table of Contents is activated. |
You can just copy the text shown in the diagram, or use your own title, table of contents and text.
You can use the files from the previous exercises and alter them if you wish.
Section Outline |
Course Outline |
Next Topic |
Links in a document will usually open the target location in the same frame. For example, if you had active links in the body of your presentation, clicking on them would cause the frame containing the body of your presentation to change but would leave the title and table of contents unchanged.In order to make the links in the Table of Contents frame open a document in the main presentation frame, it is necessary to name the frame and to use the TARGET attribute on the <A> tag or specify a target for ALL links on a page with the <BASE> tag.
- TARGET
- The TARGET specifies the NAME attribute of the frame in which the referenced page should be displayed. For example:
<A HREF="intro.htm" TARGET="Main">Section 1</a>
would be required to cause the page stored in intro.htm to be displayed in the frame with the NAME attribute value of "Main". The Main frame must be defined by a tag like the following:
<FRAME SRC="..." NAME="Main">
- <BASE TARGET="Main">
- The <BASE> tag should be included within the <HEAD> element. If you include this tag, you do NOT need to add the TARGET attribute in <A> tags unless you wish to open the link in a different frame.
- NAME
- The NAME attribute is used in the <FRAME> tag to associate a name with the frame. It is not necessary unless the window is to be updated by links in another frame. It IS necessary if you want update the window through the TARGET attribute.
<A HREF="intro.htm" TARGET="Main">Section 1</a>
Skip Practice |
Section Outline |
Course Outline |
Next Topic |
The usefulness of frames is subject to considerable debate. Frames give you the ability to keep part of your page visible on the screen at all times while scrolling through other part of your site. For complex documents, the table of contents can be displayed side-by-side with the document contents. This can be very useful in some applications. Some of the disadvantages (that you must weigh against the advantages) are:
- Older browsers (and text only browsers) cannot display frames. Depending on who you wish to use your page, you will have to provide a "non-frame" document to allow those using older browsers to read your web site.
- Three frames are essentially three pages and thus take longer to open than one. Those reading your web site through telephone line and modem may find the loading time prohibitive.
- Navigation can be a problem. You must carefully plan the layout of your frame content so that those reading your site can understand how to navigate.
- Printing pages made up of frames is confusing unless you remember that it is usually a frame that prints not the browser window. As soon as the reader clicks inside a frame, that frame becomes active. In most browsers there will be a change in the border colour or width to indicate the active frame. When you look at the file menu in newer browsers, you will see the option Print Frame instead of the usual Print option. In older browsers the usual Print option is displayed. Regardless of the actual text on the menu, it will be the document displayed in the active frame that is printed.
In some browsers, if you print a page BEFORE clicking on any frame, the browser window is printed instead of any individual frame.
Instead of using frames, you might consider using tables instead. The <TABLE> tag is supported by far more browsers than frames are. As always, keep your target audience in mind when designing on the web, and provide those with slower machines, smaller screens and expensive modem connections an alternative. Tables often offer a more "user-friendly" alternative to frames.
If you wish to view (or print) the HTML version of a document displayed in a frame, go to the View menu and choose View Frame Source.
References:
- Netscape HTML Reference Manual
(http://developer.netscape.com/library/documentation/htmlguid/)
This is Netscape's online HTML Tag Reference. All HTML tags and their attributes are described in this document. Click on the "Frames" link to get to the tags used to create frames.- Webopaedia.com - Frames page
http://webopedia.internet.com/TERM/f/frames.html
The Webopeadia is an online reference book for WWW terminology. Their entry under "Frames" includes a description of frames, their purpose and a good list of online tutorials to help you learn more about using frames on your web pages.- Virtual Library of WWW Development - HTML Forms Introduction
http://www.stars.com/Authoring/HTML/Frames/
This simple introduction to forms includes a quick reference quide and a number of annotated examples.- Examples of poor use of frames Here is another individual's opinion on the use of frames. Please read it if you are considering a web site design which will use frames.
Forms in HTML |
Basic Form Elements
Creating a Form FormMail Script Setup Tailoring FormMail Output References |
Section Outline |
Course Outline |
Next Topic |
HTML Form elements make it possible for readers of your web page to enter information that can be captured and processed. Standard form elements include radio buttons, check boxes and text boxes. You can use these elements to create questionnaires, quizzes and set variables used in (client-side) scripts. You use simple HTML tags to add these elements to a web page. The two major browsers have supported form elements since versions 2.
Some form elements:
The action associated with the Submit button on a form requires a CGI program that must be installed on your web server. Writing CGI scripts is not a simple matter unless you are already familiar with programming. You should consult your web server administrator (web master/webster) before undertaking the development of a CGI script. There are an increasing number of reliable and freely available scripts. The References section includes a number of WWW sites which distribute these scripts.
You should be aware that by filling out a form and submitting it, you are sending information to a remote computer system where it can be stored and reused. Although a CGI program cannot obtain personal information you do not enter into the form, there are a number of system variables (like the name of your service provider) that are accessible. We discuss these later in the workshop. For now, in addition to taking care about sensitive information like credit card numbers, you should also consider carefully before supplying your email address on a form. If you are sure who is controlling the information received from the form, there is little concern. If you do not know who is receiving the information, it would probably be best not to supply it.
Skip Practice |
Section Outline |
Course Outline |
Next Topic |
Every form begins with a <FORM> tag and ends with a </FORM> tag. The <FORM> tag must specify the URL of the CGI script that will process the content of the form. For now, you will use the following tag which defines the ACTION attribute as the ShowVars script and the METHOD attribute as "post". Details of these attributes will be presented in the next section - FormMail Script Setup.
<FORM ACTION="http://web.uvic.ca/cgi-bin/ShowVars.pl" METHOD="post">The body of the form consists of text and a variety of input fields. There are four different types of input field you might want to use, depending on the purpose of your form.
- Text Input:
- There are two types of text input field. A text box is intended for text that is relatively short. This type of field would be appropriate for entering a name, phone number or email address.
<INPUT TYPE="text">A text area is used for open-ended responses (comments) when the amount of text may be quite lengthy. This type of field displays a text box which is scrollable and will accept any amount of text. <TEXTAREA> ... </TEXTAREA>
- Radio Buttons:
- Radio buttons are clickable circles which are appropriate for multiple choice responses where only a single response is accepted. One tag produces a single radio button. You will use several tags for each multiple choice question.
<INPUT TYPE="radio">
- Check Boxes:
- Check boxes are clickable squares (similar to radio buttons) which are appropriate to use for multiple choice responses where more than one response will be accepted. One tag is used for each check box.
<INPUT TYPE="checkbox">
- Selection Menus:
- Selection Menus are another way of presenting multiple choice questions. The <SELECT> tag is used with several <OPTION> tags to produce a menu (either fully visible or in a "drop-down" format) of choices that the reader can select from.
<SELECT> ... <OPTION> ... <OPTION> ... </SELECT>
Variable Names
Each value that is entered on a form must be named so that it is accessible to the processing script. Each tag that defines an input area must include a name for the input field in its NAME attribute. For example, a text input field called "lastname" would be defined by the tag:<INPUT TYPE="text" NAME="lastname">Radio buttons are usually used when only one response (out of several) is acceptable. On the web page, only one of a set of radio buttons will be "on". If you click another button, it will be "on" and the previous button will be "off". To create this effect, make sure the input tags for all of the responses have the same name. Here is an example (the VALUE attribute is discussed below):Check boxes are conventionally used when more than one response to a question can be accepted. In this case, you must give a different name for each response. Here is an example:<p>Which university did you attend? <INPUT TYPE="radio" NAME="university" VALUE="ubc">UBC <INPUT TYPE="radio" NAME="university" VALUE="sfu">SFU <INPUT TYPE="radio" NAME="university" VALUE="uvic">UVIC <INPUT TYPE="radio" NAME="university" VALUE="other">other
<p>Which of the following courses did you take? <INPUT TYPE="checkbox" NAME="biology">Biology <INPUT TYPE="checkbox" NAME="chemistry" >Chemistry <INPUT TYPE="checkbox" NAME="history" >History <INPUT TYPE="checkbox" NAME="english" >English
Variable Values
Data is collected from the form elements and stored in the variables (field names) in the HTML tags. The value of a text field is taken from the input typed by the reader. For radio button input fields you must supply the value associated with each radio button in the VALUE attribute of the INPUT tag. For example (taken from above):
<INPUT TYPE="radio" NAME="university" VALUE="uvic">UVICThe variable (field) named "university" will have a value of "uvic" if the associated radio button is selected when the form is submitted. If you omit this value, the variable will simply be "on" or "off".For check boxes, you can either supply a value in the same way as for radio buttons or leave out the VALUE attribute. If you leave the VALUE attribute out, the variable will get a value of "on" if the check box is checked. The variable will not have any value if the associated check box is not checked (whether or not you have supplied a value).
Skip Practice |
and a Reset button with the tag:
<INPUT TYPE="reset">
Make sure the buttons are placed to your satisfaction on the web page.
Section Outline |
Course Outline |
Next Topic |
Browsers (that support forms) will automatically extract the information entered on a form and send it, labelled with the variable names you supplied, to the URL pointing to the appropriate CGI script (the action). The URL for the script you wish to use must be included in the ACTION attribute on the <FORM> tag.
<FORM ACTION="http://web.uvic.ca/cgi-bin/ShowVars.pl METHOD="POST">
The availability of CGI scripts will vary between servers and is controlled by the web master. There are two CGI scripts available on the main UVic server:
- ShowVars: For testing your form.
http://web.uvic.ca/cgi-bin/ShowVars.pl
- FormMail: For capturing data from your form.
http://web.uvic.ca/cgi-bin/FormMail.plThe previous exercise used the ShowVars script to show you the relationship between variable names and values. The ShowVars script captures all of the variable information sent from the browser and then sends a formatted web page back to your browser so you can see what information was captured. The script does nothing else. It is designed only for testing forms. For this reason, you can submit a form to this script from anywhere (including your local system). [Please note that you CANNOT submit a form to the FormMail script unless the form is located on UVic's central server.]
The FormMail script captures data from a form just as the ShowVars script. However, instead of sending your browser a web page containing the variables, it sends a formatted list of variables and values to an electronic mail address. The FormMail script provides a way to collect information entered onto your form by readers anywhere in the world. The file you receive can then be processed by any other software you have available to you.
Hidden Fields
The FormMail script requires a number of variable values that you do not want set by those submitting the form. You can set fixed values for variable names by using hidden input fields. To use the FormMail script, you must specify the email address that is to receive response forms as the value of the variable "recipient". It is also useful to set the variable "subject" so that you can identify form submissions when they appear in your email.
You set these values by adding the two tags below to your form. There is no affect on the appearance of your form.
<INPUT TYPE="hidden"
NAME="recipient" VALUE="YOURNAME@uvic.ca"><INPUT TYPE="hidden"
NAME="subject" VALUE="FORM TITLE">
Required Fields
You can optionally make one or more field required, so that a user cannot submit the form without filling out the field. For example, in some applications, you might want to make the user's name required. You make a field required by adding a hidden field named "required" and specifying the value as the required variable name - in this case "name".
<INPUT TYPE="text" NAME="name">
<INPUT TYPE="hidden" NAME="required" VALUE="name">
Skip Practice |
Background information and directions for uploading files can be found by linking to the File Transfer section of the Internet Tools workshop.
For more information on uploading files and setting file permissions see the workshop Maintaining a Web Site on a Unix Server.
Section Outline |
Course Outline |
Next Topic |
The documentation for the FormMail script and some working examples can be found at: http://web.uvic.ca/cass/docs/FormMail.html. The following are a few features of the script you may find useful."Thank-you" Page
After a user clicks the Submit button, they will see a "standard" thank-you screen, listing all of the variables they entered. If you would prefer to have the user see your own "thank-you" (or some other) message instead, you can set the value of the variable "redirect" to an URL of your choice. For example:
<INPUT TYPE="hidden" NAME="redirect" VALUE="thankyou.html">
After the form is submitted, the document called "thankyou.html" will be displayed. Note that the document will not display the values of the form variables.
Alternately, you might simply want to change the text of the "thank-you" message or to provide a "return" link from that message. Hidden variables can be set to change the "title" (=text) of the message and the "return" location as follows:
<INPUT TYPE="hidden" NAME="title" VALUE="Thank-you for responding! - the Editor">
<INPUT TYPE="hidden" NAME="return_link_url" VALUE="http"//web.uvic.ca/comped/online/">
<INPUT TYPE="hidden" NAME="return_link_title" VALUE="Back to Computer Education Workshop Page">Ordering Variables
By default, the variables on a form will be listed in a random order in the email message you receive. If you have more than a few variables, or if you intend to do some automated processing of the data, you should consider ordering the variables. Variables can be sorted in alphabetical order by using the following hidden field:
<INPUT TYPE="hidden" NAME="sort" VALUE="alphabetic">
By naming variables with some care and aforethought, you can ensure that the email list you receive is as easy to use as possible.
There are a number of other attributes that will allow you to change the page background and colours. You will find them in the documentation for the FormMail script at: http://web.uvic.ca/cass/docs/FormMail.html
Skip Practice |
[Remember: You must upload the file again if you make changes on your local microcomputer. You may edit the file on the UNIX server if you are familiar with using pico].
Section Outline |
Course Outline |
Very often, people design forms when an email message would have been sufficient. If you only wish to get a person's name and address, for example, asking for e-mail may take much less overhead (server, your time, customer's time).HTML forms can provide a variety of functions including database searches if special purpose CGI programs are available. Writing CGI programs is NOT in the scope of this course, though some of the references below provide an introduction to the topic. You should contact the Web master for your server to find out what programs are available and how to go about developing new programs.
Here are some references which will provide you with more detailed information about HTML forms and CGI programs (scripts).
Forms
- The documentation for the FormMail script and some working examples can be found at: http://web.uvic.ca/cass/docs/FormMail.html
- Netscape HTML Reference Manual
(http://developer.netscape.com/library/documentation/htmlguid/)
This is Netscape's online HTML Tag Reference. All HTML tags and their attributes are described in this document. Click on the "Forms" link to get to the tags used to create forms.- Webopaedia.com - Forms page
http://webopedia.internet.com/TERM/f/form.html
The Webopeadia is an online reference book for WWW terminology. Their entry under "Forms" includes a description of forms, their purpose and a good list of online tutorials to help you learn more about forms.- University of Kansas Introduction to CGI Scripts and HTML Forms
(http://www.cc.ukans.edu/info/forms/forms-intro.html)
This document is a good introduction to how CGI scripts work and how you can use Forms to pass data to a script.- NCSA Mosaic Fill-out Form Support
(http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html)
NCSA Mosaic was one of the first graphical web browsers. Their introductory review of fill-out forms includes numerous examples. Note: NCSA is well-known for its good web user documentation.- Virtual Library of WWW Development - HTML Forms Introduction
http://www.stars.com/Authoring/HTML/Forms/
This simple introduction to forms includes a quick reference quide and a number of annotated examples.CGI Scripts
- NCSA CGI Documentation http://hoohoo.ncsa.uiuc.edu/cgi/overview.html
- Matt's Script Archive
http://www.worldwidemart.com/scripts/
A source of (free) CGI scripts.- A Webreference.com - CGI Resources
http://webreference.com/programming/cgi.html
This site includes links to tutorials, reference guides, examples, free scripts and FAQ files related to creating and using CGI scripts.
http://www.sidestreets.com:8080/~8- And, always, check out Yahoo!'s list of CGI resources.
The End -
Back to Course Contents |