Forms

Forms in HTML are different from the forms found in Visual Basic and other Windows-based applications. In Visual Basic, a form is a visible container upon which controls are placed. In HTML, however, forms are principally a technique for gathering input data to pass to a back-end server. Forms are defined in HTML with the <FORM></FORM> tags. Typically, the <FORM></FORM> tags have the following syntax:

<FORM NAME="string" ACTION="string" METHOD="string"></FORM> 

The NAME attribute is the name of the form (the name you refer to in VBScript), the ACTION attribute is the URL of the back-end process to receive the form data, and the METHOD attribute is the method of data exchange between the client and the server.

Typically, controls are placed between the form tags and are contained by the form. These controls are normally used to gather data and initiate the passing of this data to the server. Passing this data to the server is known as submitting a form. Submitting is accomplished through the use of a Submit control, which is one of the intrinsic controls supported by the Internet Explorer. The following code is an example of a form with a text control and a Submit control:

<FORM NAME="MyForm" ACTION="http://NT_SERVER/mystuff" METHOD="POST">
<INPUT TYPE="TEXT" NAME="TextField">
<INPUT TYPE="SUBMIT">
</FORM> 

In this example, the form will send the data from the TextField text control to the mystuff executable when the Submit button is clicked. The METHOD attribute can be either POST or GET, depending upon how the information is to be handled. The POST method sends data to a back-end process, and the GET method appends the arguments to the URL and opens the URL. Regardless of the method, the form data is always passed in a plain text format as FIELD=VALUE for each input field in the form. The back-end program can then parse the text and take action based on the data.

KEY CONCEPT:When a form is submitted to a back-end process, the data takes the format FIELD1=VALUE1&FIELD2=

VALUE2…&FIELDn=VALUEn. 

The NAME attribute of a form can be used in VBScript. The NAME attribute allows the form to behave like an object that can be accessed in code. Once the object is accessed, you can address the controls on the form in the familiar form.control.property syntax of Visual Basic for Applications. The Document object of the ActiveX Scripting model provides a way to access the form object by setting a variable equal to Document.formname. As an example, the following code puts text into the text control of the form:

<SCRIPT LANGUAGE="VBScript">
    `Notice the use of the Document object to
    `obtain a reference to the form
    Document.MyForm.Text1.Value="New Text"
</SCRIPT> 

Once the information for a form has been entered, the data can be passed to a process running on a back-end server. When the data is passed, you can use several tools to receive data on the back end. If your server is a Windows NT platform running IIS, you can access a database directly through the Internet Database Connector (IDC) or through OLEISAPI, a dynamic-link library hosted by IIS. IDC and OLEISAPI are discussed in detail in Chapter 5, along with complete code examples.

© 1996 by Scot Hillier. All rights reserved.