7
If minimal.pl is invoked with no parameter data as
input, it will send back an HTML form using the
subroutine &sendform. The listing in part 4 shows
that subroutine.
The HTML form in this section will need to be
modified by the user. The SAS program which
processes it will also need to be changed.
The &sendform routine first sends back a response
header which is
Content-type:text/html\n\n
(“
\n
” is a line ending), and should not be changed.
All of the HTML for the form document is found
between the markers
<<HTML_FORM
and
HTML_FORM
and is typed just as if it were in a file by
itself with the exception that the action parameter of
the form tag contains
$scriptloc
. This is a Perl
variable name which will be replaced by the string
entered for it at the top of the program. It contains
the URL of minimal.pl.
The form in this example defines 3 parameters:
• greet - in the first select box can take on multiple
values.
• to - in the second select box can only have a
single value.
• number - in a text box allows a user to enter any
value
Having the form as part of the CGI script program
has potential advantages besides housekeeping
ones. The script could run a SAS program or use
the SAS SQL Library for C to send an SQL query to
a SAS/SHARE*NET server. Data from this external
procedure could be used to generate a form. A
modified version of this Perl script could also handle
data validation by sending back a form with values
from the previous submission and error messages.
Building a form from a query to a SAS program
could keep it current automatically. For example a
SELECT box could be populated with a current list
of parts from a database or the current years in a
file.
Multiple occurrences
The trickiest part of handling form parameters in
SAS is what to do with multiple occurrences of
parameters like
greet
. If the user, for example,
selects “Kansan”
1
and “French”, the Perl script will
receive greet=Howdy&greet=Bonjour.
1
Minimal.sas and the form with it are really a
“Hello World” application. Translated into Kansan that’s
“Howdy Folks”.
The CGI component of the SAS/IntrNet product
would handle the preceding multiple occurrences by
defining the following sequence.
%let greet=Howdy;
%let greet0=2;
%let greet1=Howdy;
%let greet2=Bonjour;
The macro variable corresponding to the parameter
name gets the first value received. Then a “0” is
appended to the parameter name and it is assigned
the number of multiple occurrences. Finally each
occurrence appears as PARAM
j
where
j
is a
sequential counter starting with 1. Minimal.pl adopts
this approach to multiple occurrences.
minimal.pl (part 4)
# ---------------------------------------------------------------------------------------
# Send back a form
# Customize this section for your application.
# Form variable names should be short enough to allow appending
# at least one digit - more if a multiple select variable.
# The variable names with appended digits must meet SAS naming
# rules for macro variable names.
# ---------------------------------------------------------------------------------------
sub sendform {
print "Content-type:text/html\n\n";
print ($BeginHtml);
print <<HTML_FORM;
<HR>
<FORM ACTION="$scriptloc" method="POST">
Send a greeting
<BR><SELECT NAME="greet" multiple >
<OPTION VALUE="Hello">Formal
<OPTION VALUE="Hi">Informal
<OPTION VALUE="Howdy" SELECTED>Kansan
<OPTION VALUE="Bonjour" >French
</SELECT>
<BR>To the planet:
<BR><SELECT NAME="to" >
<OPTION VALUE="World">World
<OPTION VALUE="Earth">Earth
<OPTION VALUE="Folks" SELECTED>Folks
<OPTION VALUE="Monde" >Monde
</SELECT>
<br>How many greetings do you want?
<br> <input type="text" name="number" value="2">
<HR>
<INPUT TYPE="submit" VALUE="Send Greeting">
</FORM>
</BODY>
</HTML>
HTML_FORM
} # end sendform
exit;