Oracle WebServer User's Guide
Forms
HTML pages can be formatted in any fashion, but remain read-only. The HTML form feature brings the added advantage of being interactive. An HTML form lets the Web user enter comments and specify database search criteria.
When a form is interpreted by a Web browser, a special graphical user interface (GUI) screen is created with text entry fields, buttons, checkboxes, pull-down menus, and scrolling lists. When the Web user fills out the form and presses a button indicating the form should be submitted, the information on the form is sent to an HTTP server for processing by a CGI (Common Gateway Interface) program. For more information on CGI, see Chapter 3, "The Oracle Web Listener".
When you write a form, each of your input items has an <INPUT> tag. When the user places data in these items in the form, that information is encoded into the form data and is known as the "value".
All form elements have Name and Value attributes. Data are sent as NAME=VALUE pairs, separated by ampersands (&), where name is given in the NAME attribute, and value is given in the VALUE attribute, or replaced by the user.
This section illustrates the basic use of HTML forms. Forms can be used for simple table searches or complex queries to relational databases.
Forms Syntax
All forms begin with <FORM> and end with </FORM>.
The syntax is as follows:
<FORM METHOD="get|post" ACTION="URL">Form_elements_and_other_HTML
</FORM>
METHOD
The request method supplies the data to the program. There are two request methods that can be used to access your forms. Depending on which request method you use, you will receive the encoded results of the form in a different way.
- GET: Information from a form is appended onto the end of the URL being requested. Your CGI program receives the encoded form input in the environment variable QUERY_STRING. Use of the GET method is discouraged.
- POST: This request method transmits all form input information immediately after the requested URL. Your CGI program will receive the encoded form input on standard input. The server will not send you an EOF on the end of the data; instead use the environment variable CONTENT_LENGTH to determine how much data you should read from standard input. This is the preferred method.
ACTION
ACTION specifies the URL being requested from the form. This URL will almost always point to a CGI script to decode the form results. If you are referring to a script on the same server as the form, you can use a relative URL.
Form Tags
TEXTAREA
The <TEXTAREA> tag is used to allow a user to enter more than one line of text in a form. The following is an example of the TEXTAREA tag:
<TEXTAREA NAME="address" ROWS=14 COLS=60>
Chicago Blackhawks
1800 Madison Ave
Chicago, Il 60612
</TEXTAREA>
The attributes included within the <TEXTAREA> tag are used to initialize the field's value. The </TEXTAREA> tag is always required even if the field is initially blank.
The following are attributes of <TEXTAREA> and determine the visible dimensions of the field in characters:
- ROWS-height in characters of TEXTAREA
- COLS-width in characters of TEXTAREA
If you want text to appear within the text area, enter it between the start and end <TEXTAREA>tags.
INPUT
The <INPUT> tag allows you to input a single word or line of text, with a default width of 20 characters. It is usually preceded with some descriptive text.
The following are attributes of <INPUT>:
- CHECKED-When present indicates that a checkbox or radio button is selected.
- MAXLENGTH-The maximum number of characters that will be accepted as input. This limits the number of characters a user can type into the field. The form will give an error beep if the user tries to enter too many characters. This can be greater that specified by SIZE, in which case the field will scroll appropriately. The default is unlimited.
- NAME-Symbolic field name used when transferring the form's contents. This attribute is always needed and should uniquely identify this field.
- SIZE-Specifies how large an area to allocate, in characters, on the screen.
- SRC-A URL specifying an image for use only with TYPE=IMAGE.
- TYPE-Defines the type of data the field accepts. Defaults to free text. Several types of fields can be defined with the TYPE attribute:
Used for simple Boolean attributes, or for attributes that can take multiple values at the same time. The latter is represented by a number of checkbox fields each of which has the same NAME. Each occurrence of a checkbox is either ON or OFF. For a multi-valued attribute, there is a checkbox for each attribute, indicating whether the attribute applies. The various attributes are associated with one another by the fact that each attribute checkbox uses the same name. Each selected checkbox generates a separate NAME=VALUE pair in the submitted data, even if this results in duplicate names. The default value for CHECKBOX is ON.
No field is presented to the user, but the content of the field is sent with the submitted form. This value may be used to transmit state information about client-server interaction, or for password information.
An image field upon which you can click with a pointing device, causing the form to be immediately submitted. The coordinates of the selected point are measured in pixel units from the upper left corner of the image, and are returned (along with the other contents of the form) in two NAME=VALUE pairs. The x-coordinate is submitted under the name of the field with .x appended, and the y-coordinate is submitted under the name of the field with .y appended. Any value attribute is ignored. The image itself is specified by the SRC attribute, exactly as for the <IMG> tag.
Same as TEXT attribute, except that password text is not displayed as it is entered.
For attributes which can take a single value from a set of alternatives. Each radio button field in the group should be given the same NAME. Only the selected radio button in the group generates a NAME=VALUE pair in the submitted data. Radio buttons require an explicit VALUE attribute.
This is a button that when pressed resets the form's fields to their specified initial values.
This button, when pressed, submits the form. You can use the VALUE attribute to provide a non-editable label to be displayed on the button. The default label is application-specific. The NAME attribute, if used, passes a name=value pair along with the submitted form.
Single line text entry fields. Use in conjunction with the SIZE and MAXLENGTH attributes. Use the TEXTAREA tag for text fields that can accept multiple lines.
- VALUE-Assigns an initial default value for the field, or the value when checked for checkboxes and radio buttons. This attribute is required for radio buttons.
Form Selection Menus
There are three types of selection menu tag for forms:
- Select: user selects from a fixed set of values represented by the option tag. This tag is usually displayed with a pull down menu.
- Select single: same as Select, but display is presented with a window with three items displayed at once . If there are more than three options, the window will have a scroll bar.
- Select multiple: allows multiple items to be selected from the menu.
SELECT
The SELECT tag allows the user to select a value from a fixed list. This is usually presented as a pull down menu.
The SELECT tag has one or more options between the start<SELECT> and end</SELECT> tag. By default the first option is displayed in the menu. The following is an example of a <SELECT> tag:
<FORM>
<SELECT NAME=group>
<OPTION> Gretzky
<OPTION> Messier
<OPTION> Coffey
</SELECT>
</FORM>
SELECT SINGLE
The SELECT SINGLE tag is the same as the SELECT tag, but options are displayed in a window with three items shown at once. If there are more than three options, the window will have a scroll bar. The SIZE tag within the SELECT tag specifies how many options will be shown in the window. The following is an example of a <SELECT SINGLE>tag:
<FORM>
<SELECT SINGLE NAME=group SIZE=3>
<OPTION> Gretzky
<OPTION> Messier
<OPTION> Coffey
<OPTION> Kurri
</SELECT>
</FORM>
In this example, the first three names would appear in the window, and a scroll bar would scroll to the last name.
SELECT MULTIPLE
The SELECT MULTIPLE tag is the same as the SELECT SINGLE tag, but the user can select more than one option in the window. The SIZE tag specifies how many lines appear in the window, and the MULTIPLE tag specifies how many options can be selected.
The following is an example of SELECT MULTIPLE:
<FORM>
<SELECT MULTIPLE NAME=group SiZE=3 MULTIPLE=2>
<OPTION> Gretzky
<OPTION> Messier
<OPTION> Coffey
<OPTION> Kurri
</SELECT>
</FORM>
Note: On some browsers, it may be necessary to hold down the CONTROL or SHIFT key to select multiple items.
If multiple items are selected, they each get passed to the server with the same name. The decoding script has to be able to recognize multiple values associated with the same name.