Thank you for your help. I am sorry I did not make my question clearly
at the first place. Our email system got some problems, so I have to
wait to send this out. Here is my script:
Thanks for posting this, though it might have been cut down quite a
bit to simply display the problem. Here follow my comments:
use warnings;
use strict;
Why are you calling this function with an '&'? That hasn't been
necessary since Perl 4, at least. This should be:
populatePostFields();
-- except actually, you shouldn't use this at all. Just replace this with:
use CGI qw/:standard/;
$title = $postFields{ "select" };
$firstName = $postFields{ "textfield1" };
$lastName = $postFields{ "textfield2" };
$email = $postFields{ "textfield3" };
$dayPhone = $postFields{ "textfield4" };
$companyName = $postFields{ "textfield5" };
$webSite = $postFields{ "textfield6" };
$question = $postFields{ "textfield7" };
$bestTime = $postFields{ "select2" };
$timeZone = $postFields{ "select3" };
$hearSource = $postFields{ "select4" };
$otherSource = $postFields{ "textfield8" };
All those variables need to be declared, with 'my'. Read 'perldoc
strict' for more information on why.
FYI, those are terrible names in the HTML! If you want to make your
script and HTML easy to maintain, rename 'select' in your HTML source
to 'title', 'textfield1' to 'firstName', and so on. Then you don't
have to use all these temporary variables! Just do:
print "Title is: ",param('title'),"\n";
or something like that. It's much more readable than:
my $title = param('select');
for what I hope are obvious reasons.
print "Content-Type: text/html\n\n";
print header, start_html("Hello, World1!");
print "Hello, World1!\n";
Above you said you were sending text/html to the browser, but you're
not actually sending it. If you mean text/plain, then say so. If you
mean text/html, then print that.
To print a text/plain content header with CGI.pm, just use:
header('text/plain')
instead of
header
above.
print "title $title, fname $firstName, lname $lastName, email
$email\n";
print "day# $dayPhone, comName $companyName, web $webSite\n";
#print "question length $string_length\n"
#print "question $question\n"
#print "bestTime $bestTime, timeZone $timeZone, hearSource
$hearSource, otherSource $otherSource\n";
sub populatePostFields {
%postFields = ();
Don't declare package variables in a sub, especially when they're not
needed.
read( STDIN, $tmpStr, $ENV{ "CONTENT_LENGTH" } );
A) What's $tmpStr? If it's another package variable, then see above--
it's not necessary, and adds to the confusion.
B) The quotes around CONTENT_LENGTH are unnecessary
C) You never check the results of the read(), so you don't know how
many bytes you actually read.
@parts = split( /\&/, $tmpStr );
I know GET queries are allowed to separate parameters with ';' as well
as '&'; are POST ones as well?
foreach $part (@parts) {
( $name, $value ) = split( /\=/, $part );
$value =~ ( s/%23/\#/g );
$value =~ ( s/%2F/\//g );
Your decoding here is painfully incomplete. There's a lot more to URI
decoding than that.
$postFields{ "$name" } = $value;
Again, quotes around the hash key are unnecessary here.
}
}
I can not print $question, so I comment it out. My guess is $question
is not properly assigned since the textfield7 has multiline (it is a
textarea in HTML).
That's possible, but what do you mean by "I cannot print $question"?
Does the program die at that point, does it print out nothing, does it
send an error message to your server's error log that says, "Sorry,
you are allowed to print out anything except $question"? Specifics
help here-- what exactly did it do, what exactly did you expect it to?
Stop trying to parse CGI input yourself; it's a much more complicated
task than you evidently think it is. Use CGI.pm instead. It's a
standard module included with Perl, so you don't even have to search
for it or try to install it. Just use it.
Also, when you tell a browser you're going to send it text/html, and
then don't, it's quite possible something quirky is going on there,
but since you don't tell us what actually happens when you try to
print out the variable in question, that's only a wild guess.
I'm certain about using CGI.pm, though.
-=Eric