Hi all,
About a week ago I post this on this forum.
"I'm new to CGI and i have a problem with the post method.
In my HTML I have a small form that uses the POST method.
The problem I have, is that in my CGI (Perl) script the string i receive from STDIN is empty. I've tried different ways to do it but it never works.
I use: read (STDIN, $input, $ENV{CONTENT_LENGTH}).
I'm able to print the content length, but $input is always empty. It prints nothing"
An export, called goBoating, post this on my thread. (I really hope you are reading this goBoating):
"
#!/usr/local/bin/perl
%FORM = &cgidecode;
# if the html form contained a 'name' input,
$name = $FORM{'name'};
sub cgidecode
{
local(%vars, $val, $key, $last, $buffer, $pair, @pairs);
# Checking the form method (GET or POST) used in the
# HTML code. POST method sends data to standard input,
# but GET adds it to the URL and stores it in
# QUERY_STRING.
if ($ENV{'REQUEST_METHOD'} eq "POST"
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else
{
$buffer = $ENV{'QUERY_STRING'};
}
# Splitting up the data fields and store
# in array @pairs, they are seperated with &
@pairs = split(/&/, $buffer);
# Splitting the variable names and the values
# and storing them in the assoc. array %vars
foreach $pair (@pairs)
{
($key, $val) = split(/=/, $pair);
$val =~ s/\+/ /g;
$val =~ s/%(..)/pack("C",hex($1))/eg;
if ($key eq $last) {$vars{$key} .= " ".$val; }
else { $vars{$key} = $val; }
$last = $key;
}
return(%vars);
}
"
I've tried to do this, but my STDIN is still empty, I think.
When I try to print $buffer, after STDIN is read in, it prints nothing.
Maybe something is wrong with my HTML form. Here it is:
"<form action="../../cgi-bin/contact.cgi" method="POST">
<input type="text" name="email" maxlength="50"><br>
<input type="text" name="onderwerp" maxlength="150"><br>
<textarea cols="25" rows="10" name="commentaar"> </textarea><br>
<input type="submit" name="zend" value="Zend">
</form>"
I realy hope you guys can help me.
Thanks a lot
Best regards,
Tijs Programming is like sex: one mistake and you have to support it for the rest of your life.
About a week ago I post this on this forum.
"I'm new to CGI and i have a problem with the post method.
In my HTML I have a small form that uses the POST method.
The problem I have, is that in my CGI (Perl) script the string i receive from STDIN is empty. I've tried different ways to do it but it never works.
I use: read (STDIN, $input, $ENV{CONTENT_LENGTH}).
I'm able to print the content length, but $input is always empty. It prints nothing"
An export, called goBoating, post this on my thread. (I really hope you are reading this goBoating):
"
#!/usr/local/bin/perl
%FORM = &cgidecode;
# if the html form contained a 'name' input,
$name = $FORM{'name'};
sub cgidecode
{
local(%vars, $val, $key, $last, $buffer, $pair, @pairs);
# Checking the form method (GET or POST) used in the
# HTML code. POST method sends data to standard input,
# but GET adds it to the URL and stores it in
# QUERY_STRING.
if ($ENV{'REQUEST_METHOD'} eq "POST"
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else
{
$buffer = $ENV{'QUERY_STRING'};
}
# Splitting up the data fields and store
# in array @pairs, they are seperated with &
@pairs = split(/&/, $buffer);
# Splitting the variable names and the values
# and storing them in the assoc. array %vars
foreach $pair (@pairs)
{
($key, $val) = split(/=/, $pair);
$val =~ s/\+/ /g;
$val =~ s/%(..)/pack("C",hex($1))/eg;
if ($key eq $last) {$vars{$key} .= " ".$val; }
else { $vars{$key} = $val; }
$last = $key;
}
return(%vars);
}
"
I've tried to do this, but my STDIN is still empty, I think.
When I try to print $buffer, after STDIN is read in, it prints nothing.
Maybe something is wrong with my HTML form. Here it is:
"<form action="../../cgi-bin/contact.cgi" method="POST">
<input type="text" name="email" maxlength="50"><br>
<input type="text" name="onderwerp" maxlength="150"><br>
<textarea cols="25" rows="10" name="commentaar"> </textarea><br>
<input type="submit" name="zend" value="Zend">
</form>"
I realy hope you guys can help me.
Thanks a lot
Best regards,
Tijs Programming is like sex: one mistake and you have to support it for the rest of your life.