next up previous
Next: Enabling Online CGI Execution Up: No Title Previous: Details

Offline Execution

Most of the development of your CGI script should be done in this mode of execution. To get offline execution, you simply run the CGI script as a normal Perl script on, for example, an IBM workstation. Suppose you execute the script add.cgi. You will get the following prompt:

(offline mode: enter name=value pairs on standard input)

If you hit at this point, the script should produce the HTML corresponding to the form that the user will use to enter input. As long as you use the routines header(), start_html(), start_form(), end_form(), and end_html() with HTML emitting functions placed between start_html() and end_html() and HTML form widgets only placed between start_form() and end_form(), the HTML produced should be valid (if not aesthetically pleasing when printed). However, this is a good way to check for run-time warnings and other problems. Continuing the above example, a would give us

Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Add Me</TITLE>
</HEAD><BODY><H1>Add Me</H1><HR><FORM METHOD="POST"  ENCTYPE="application/x-www-form-urlencoded">
<P>First Number: <INPUT TYPE="text" NAME="field1" VALUE=""></P>
<P>Second Number: <INPUT TYPE="text" NAME="field2" VALUE=""></P>
<P><INPUT TYPE="submit" NAME="add" VALUE="add"> <INPUT TYPE="reset" VALUE="clear"></P>
</FORM><HR></BODY></HTML>

To make your script execute as if it received user input, enter the -NAME that you gave each widget followed by an equals sign and a test value you would like it to have. Note that giving a widget a name containing spaces will work in online mode but will be a problem in offline mode. If the value has spaces in it, like hello there, it should be enclosed in quotes. When you are done with the list, type . For add.cgi, we could enter

field1=3
field2=4

The script would emit:

Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Add Me</TITLE>
</HEAD><BODY><H1>Add Me</H1><P>3 + 4 = <B>7</B>
</P></BODY></HTML>
Again, it could also generate Perl warnings or programmer-defined error messages.

What if you have a widget that allows the user to select several values to return to the CGI script (for example, a checkbox_group)? Then you simply repeat the widget-name-equals-value combination for each value:

operating_systems=AIX
operating_systems='Sun OS'

Instead of typing in the data each time, you can create several files of the proper format and then run the script by redirecting standard input to come from a file. For example, if we have a file called input.batch, with the following contents:

N03=yes
G11=yes
QN03=1
QG11=3
name="Krishna Moorthy"
address="CS Dept, RPI"
city=Troy
state=NY
zip=12180
comm_stat=Noncommercial
username=krishm
password=youkilledkenny
password2=youkilledkenny

we can run cart.cgi as cart.cgi < input.batch.


next up previous
Next: Enabling Online CGI Execution Up: No Title Previous: Details
Moorthy
6/3/1998