Gunner
08-06-2003, 05:25 AM
I found a script that sends info from a form to a flat file then sends the user to a success or failure page generated by the script and it has worked great for a couple of years. I am trying to mod it to redirect the user to pages I have written.
I have done some research and found several ways of doing it, My problem is I cant get any to work. Here is what I have so far:
# this is where the info will be written to - you need to specify a real directory
$file ="/path/to/results.txt"; #must be read/writable
#
##################################################################
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
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;
$contents{$name} = $value;
}
}
chop($date = `date`);
# Now with the program
###########################################################
# Has to output a Content-type
print "Content-type: text/html\n\n ";
# Check to see if all required information was entered
# If you want a field to be required, add it here.
&no_cigar unless $contents{'comments'};
sub no_cigar
{
print $query->redirect(-uri=>'http://www.yourdomain.com/failure.html', -nph=>1);
exit;
}
# They go here if the form was submitted
# successfully.
print $query->redirect(-uri=>'http://www.yourdomain.com/success.html', -nph=>1);
#Prints to the file
#print "Content-type: text/plain\n\n ";
open(OUTPUT, ">>$file");
print OUTPUT "_______________________________\n";
print OUTPUT "Date: $date\n";
print OUTPUT "FORM NAME: $contents{'formname'}\n";
print OUTPUT "COMMENT: $contents{'comments'}\n";
close (OUTPUT);
exit;
All I get is a blank page and the address bar still points to the script!
Any help would be great!
I have done some research and found several ways of doing it, My problem is I cant get any to work. Here is what I have so far:
# this is where the info will be written to - you need to specify a real directory
$file ="/path/to/results.txt"; #must be read/writable
#
##################################################################
if ($ENV{'REQUEST_METHOD'} eq 'POST')
{
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;
$contents{$name} = $value;
}
}
chop($date = `date`);
# Now with the program
###########################################################
# Has to output a Content-type
print "Content-type: text/html\n\n ";
# Check to see if all required information was entered
# If you want a field to be required, add it here.
&no_cigar unless $contents{'comments'};
sub no_cigar
{
print $query->redirect(-uri=>'http://www.yourdomain.com/failure.html', -nph=>1);
exit;
}
# They go here if the form was submitted
# successfully.
print $query->redirect(-uri=>'http://www.yourdomain.com/success.html', -nph=>1);
#Prints to the file
#print "Content-type: text/plain\n\n ";
open(OUTPUT, ">>$file");
print OUTPUT "_______________________________\n";
print OUTPUT "Date: $date\n";
print OUTPUT "FORM NAME: $contents{'formname'}\n";
print OUTPUT "COMMENT: $contents{'comments'}\n";
close (OUTPUT);
exit;
All I get is a blank page and the address bar still points to the script!
Any help would be great!