Using Web Forms with RapidQ - Part I

Overview

Two key components to using RapidQ with Web Forms are the Web Browser "front end" and the RapidQ CGI program that takes action on the data that is entered. The web page, written in HTML code, allows us to create a data entry screen, and the RapidQ CGI program gives us the ability to do something with that data. CGI stands for "Common Gateway Interface" and in this case, is a RapidQ program that runs behind the scenes when a web form is filled out and submitted.

The Web Page

Creating a Web form allows an internet user to enter data into various fields. Applications for this are commonly seen as "guest books", reply forms, "contact us" forms, web e-mail processes, and many other database uses. A form is written in HTML code and when submitted to the web server (typically with a "submit" button), has a certain "action" associated with it. In the simplest example, the action could be the command and this action would send a long string of text representing all of the data entered in the form. It isn't pretty, but it works.

Here is a sample web page form:

<html>
<form method="POST" action="mailto:">
Enter your Name:<input type="text" name="Name" length=20><br>
Enter your e-mail:<input type="text" name="email" length=20><br>
<input type="submit" name="submit" label="submit">
</form>
</html>

This is not an HTML class, but let's spend a moment reviewing how the data starts its way "in" to the server. Notice the input fields that describe type=, name=, and length=. The name of each field is what we will use later when we process this information. In the "mailto" example shown above, the data might look something like this:

Name=Jane+Smith&email=

This is what would come in to your mail if the form used the "mailto" action as shown. If there were numerous fields in the form, you can see that it would not be a friendly visual experience. Getting something like this from a long string of text in e-mail into a meaningful data file would also require further action, so just take the e-mail example as a type of action for illustration purposes only.

Back to the string of data, notice the format shows fieldname=value. Each field is separated by a & and each word in a field is separated by a + instead of a space. These delimiters will be used by the CGI program to parse (split up) the string into meaningful data. That is the main purpose of the CGI program - to parse the data into fields and to allow us to do something with those fields.

Typical CGI programs on Unix systems are written in the Perl or 'C' languages, which are not very easy to read or maintain by the average computer person. Windows CGI programs could be Perl, 'C', ASP, CFM or other languages, but now enter RapidQ !! (Sound the bugles... King William, take a bow! Ok, back to work).

The CGI Program

RapidQ gives us a better way of processing web data in a format that is easy to read and maintain. That's the advantage over other languages. Similar to a regular RapidQ program, there is an include statement for CGI programs. The CGI.INC file should be used as the first statement in the program, and it uses certain parts of the environment to interface with the web form.

Here is a sample CGI program written in RapidQ:
'-------------------------------------
$INCLUDE "cgi.inc"

' call the initialization subroutine
InitCgi()

' send a title and a heading for the screen
sendheader("CGI Test Title!")
sendb "<h1>RapidQ CGI Test.</h1>"

' call the function to grab the data entered on the web form
username$ = GetCgiValue("Name")
useremail$ = GetCgiValue("Email")

' do something with the data to communicate back with the user
sendb "Hello " + username$ + "!<p>"
sendb "Thanks for signing up with us. Your free newsletter will be e-mailed to "
sendb useremail$ + ", which is the address you have provided to us.<p>"
sendb "Have a great day!"<p>

sendfooter()
end
'-------------------------------------

Compile this program and place it in the "cgi-bin" directory of your home page. Whatever name is given to this program, such as "cgitest.exe" should be placed with the action command in the HTML form. For example, the line would be:

<form method="POST" action="/cgi-bin/cgitest.exe">

instead of the "mailto" syntax in our example above.

This is just a small example of how CGI programs can be created. Take the time to read through the CGI.INC file and you will see a list of environment variables that you can use. Display them in a test CGI program and discover useful ways to work with them. For example, it is possible to identify the address of the person completing the web form, along with other meaningful information.

The Test Environment

A decent way to setup a local development environment is to use the Xitami webserver (or the MS personal web server) running on your local Win95/98/NT work station.  Put the .EXE file in the CGI-BIN directory and the .HTM file in the "webpages" directory.  Point your browser at http://.44/formtest.htm  (where .44 is your local IP address) and "formtest.htm" is the web page form.

In this fashion, your single PC is the client and the server and you can edit, compile, and run the program quickly without having to FTP programs and web pages to your "live" web server.  You can also setup a one line batch file in your path as follows:

rcc.bat
rc.exe -Ic:\progra~1\rapidq -Lc:\progra~1\rapidq  %1

This way you can be in the cgi-bin directory editing your program and compiling it with the statement "rcc cgidemo.bas".  The "bat" file will look to your rapidq directory for the include and library files. Note that rc.exe also needs to be in your path. Remember to "refresh" your browser screen if you make any changes to the web page.

The End.

created by "Scott" 4/21/00