|
|
||||||||||||
Chapter 7: FormsForms add a degree of interactivity to your webpages. They allow visitors to send information to you directly from within webpages themselves (with the aid of a mailing script installed your website's server), or can be used alongside a JavaScript running on your webpage. Forms are similar to the dialog boxes in BestAddress and other programs where you enter information and click a button which results in a task being performed based upon the information you specified. A form can be described as a webpage equivalent of a dialog box. There are a variety of controls that can be placed on a form including buttons, text boxes, check boxes, option boxes, list selections and drop down lists. Among other uses, forms are commonly used in webpages for guest books where visitors can provide comments, and send in details about themselves. Creating a Form FieldYou can easily add form fields and controls to your webpage by choosing an option from the Insert menu. In this tutorial, you will be introduced to the code that makes your forms work. A form field contains all the controls (such as text boxes and buttons) and can be inserted anywhere within the body of a webpage. To define a form field, use the So that the web browser knows where the information typed into a form is to be sent, you will need to use the
The The The Submit ButtonMost dialog boxes have a button which the user clicks for a task to be performed. In forms these are called submit buttons. The submit button is specified using the following code, and is placed anywhere between the
When added to a form, the button's caption is automatically set to Submit. If you what to change it to something else, you can use the
The following example demonstrates the use of a simple form containing only a submit button:
The sample above won't do anything because you need to specify a valid URL for the
The Reset ButtonYou can add a reset button to your forms that when clicked, causes the form to be cleared and reset to the default values just like when the webpage first loaded. A typical reset button's code may look as follows:
Text BoxesIf you want visitors to your site to provide you with simple text entries, such as their name or email address, use text boxes. The basic format of a text box is:
The
To add a label before the start of the text box so that the visitor knows what to enter, simply write it before the text box:
The following example demonstrates the use of a simple form containing three text boxes, a submit button and a reset button:
When displayed in a Web browser, the example above would look something like this:
Default values: Text boxes can have a default value that appears when the webpage first displays and before the visitor types anything by using the
Setting the size: If you want your visitors to enter a long string of text such as a website address, or a short amount of text such as their postal code, you can size the text box appropriately using the
Limiting the length of text: Sometimes you might like to limit the maximum number of characters a visitor can type. To do this, use the
Text AreasIf you want visitors to be able to type large amounts of text, a standard text box is not sufficient since they only support a single line. In this case, you would use the You can specify the size of the text area box based upon the number of lines using the Don't forget to specify the end element ( Check BoxesTo allow users to enter yes/no or true/false information, use check boxes. A check box's code typically looks like this:
If you want a particular checkbox to be checked when the webpage loads, simply include the
Option ButtonsAlso known as radio buttons, option buttons are used when a user can choose one option from multiple choices:
The The following example demonstrates the use of two option button groups in a form:
When previewed in a browser, the above example will look something like this:
Scrolling and Drop Down ListsAlthough radio buttons are suitable for a small number of options, they are difficult to manage if there are more than around four per group. In this instance, lists are more suitable. An example of a list's code is as follows:
As you can see, the actual list is defined using the The Submitting your FormsAt the moment you can produce forms, but you have no way of submitting them. You will need to use a special program that is usually stored on the computer that hosts your website. As these programs are usually produced by your web hosting provider, the method of making them submit your forms will differ. You will need to contact your web hosting provider for more information. If your web hosting provider does not support these, there are a number of free programs available for you to use on the Internet. Hidden FieldsYou can also add hidden fields to forms that aren't displayed by the browser, but are submitted with the form. They have a number of uses, usually specific to the form handling program you are using. A sample hidden field is shown below:
Where to from here?Forms make it easy for visitors to contact you. In the next chapter, Chapter 8: Frames, you will learn about frames - a concept that will significantly ease the development process for large websites. |
||||||||||||
![]()
A Multimedia Australia website.
Copyright © 2001 - 2010 Multimedia Australia Pty. Ltd.
Australian Company Number 096 830 394. All rights reserved.
ABN 78 096 830 394
Terms of use. Disclaimer. Privacy Statement.