develooper Front page | perl.libwww | Postings from July 2001

Perl

From:
Syed Shah
Date:
July 22, 2001 16:30
Subject:
Perl
Message ID:
4.3.1.2.20010722192905.00abde20@mail.cmich.edu
I ran the following in Netscape. However, when I click submit it does not 
anywhere. The CGI program is in the same directory as this file. Please 
help. Thanks.

<HTML>
<HEAD>
<title>A SURVEY FORM</TITLE>
</HEAD>
<BODY>
<H2> A Survey Form</h2>
<FORM ACTION="survey.cgi" METHOD="post">
<P>Name: <INPUT TYPE="text" NAME="name" SIZE=30 MAXSIZE=50>
</P>
<P> <INPUT TYPE="checkbox" NAME="Purchaser" Value="yes">
I am authorized to make purchased.
</P>
<P>
IT Budget:<BR>
<INPUT TYPE="radio" NAME="budget" VALUE="10000">Less Than $10,000<BR>
<INPUT TYPE="radio" NAME="budget" VALUE="100000">From $10,000 to $100,000<BR>
<INPUT TYPE="radio" NAME="budget" VALUE="1000000">From $100,000 to 
$1,000,00<BR>
</p>
<p>
Current Job Responsibility:
<SELECT NAME="JOB" SIZE=1>
         <OPTION VALUE="senior">Senior Management
         <OPTION VALUE="management">Management
         <OPTION VALUE="engineer">Engineer
         <OPTION VALUE="conultant">Consultant
</SELECT>
</P>
<p>
Comment:<BR>
<TEXTAREA NAME="comments" WRAP="virtual" cols=60 rows=10></TEXTAREA>
</p>

<p>
Color:<BR>
<SELECT NAME="color" SIZE=1>
         <OPTION VALUE="red">Red
         <OPTION VALUE="blue">Blue
         <OPTION VALUE="yellow">Yellow
</SELECT>
</P>

<p>
Operating System:<br>
<SELECT NAME="operating-system" SIZE=4 MULTIPLE>
         <OPTION VALUE="macos">MAC
         <OPTION VALUE="linux">Linux
         <OPTION VALUE="freebsd">FreeBSD
         <OPTION VALUE="windows">Windows
</SELECT>
</P>
<P>
<INPUT TYPE="submit">
<INPUT TYPE="reset">
</P>
</FORM>
</BODY>
</HTML>

The CGI file is:

#!c:\perl\bin\perl.exe
#/usr/local/bin/perl

print "Content-type:text/html\n\n";


read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {

         ($name, $value) = split(/=/, $pair);

         $value =~ tr/+/ /;

         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

         $value =~ s/\n/ /g;     # replace newlines with spaces

         $value =~ s/\r//g;      # remove hard returns

         $value =~ s/\cM//g;     # delete ^M's

         $FORM{$name} = $value;

}


open(OUTF,">>survey.out") or dienice("Couldn't open survey.out for

writing: $!");


# This locks the file so no other CGI can write to it at the

# same time...

flock(OUTF,2);
# Reset the file pointer to the end of the file, in case

# someone wrote to it while we waited for the lock...

seek(OUTF,0,2);

print OUTF "$FORM{'name'}|$FORM{'email'}|";

print OUTF "$FORM{'howreach'}|$FORM{'rating'}|";

%boxes = (      "des" => "Website Design",

                         "svr" => "Web Server Administration",

                         "com" => "Electronic Commerce",

                         "mkt" => "Web Marketing/Advertising",

                         "edu" => "Web-Related Education" );

foreach $key (keys %boxes) {

         if ($FORM{$key} == 1) {
                 print OUTF "$key,";

         }

}


print OUTF "|$FORM{'comments'}\n";

close(OUTF);


print <<EndHTML;

<html><head><title>Thank You</title></head>

<body>

<h2>Thank You!</h2>

Thank you for your feedback.<p>

<a href="index.html">Return to our home page</a><p>

</body></html>

EndHTML


sub dienice {

         my($msg) = @_;

         print "<h2>Error</h2>\n";

         print $msg;

         exit;

}




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About