Link to home
Start Free TrialLog in
Avatar of craigs052998
craigs052998Flag for United States of America

asked on

error in data

I have a form that has a box on it called email.  when the user enters in their email address and submits the form the address is printed: user%40server.com  Is there a reason why I am getting %40 instead of @ ?  And is there a way in the script to prevent that ?
ASKER CERTIFIED SOLUTION
Avatar of b2pi
b2pi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of craigs052998

ASKER

when you refer to variable do you mean perl or form?  the item name on the form is email and I want the script to print it on the message being mailed to the proper person.  the line in my script is:

print OUT "Users e-mail address:     $form{'email'}\n";

are you saying do:
print OUT "Users e-mail address:   $email = uri_unescape($email)\n";

to get it to print right ?
Unless you're going to use it later, you don't need to assign it, thus

print OUT "Users e-mail address: uri_unescape($email)\n";


will do
that didn't work.  I got    uri_unescape(subject) in my from box with the following code:

print OUT "From:        uri_unescape($email)\n";

You did put the



    use URI::Escape;

line at the top of your script?

What happens if you do:

$email = uri_unescape($email);
print OUT "From: $email\n";


still no good.  following is my script down to the point email(name) is used.  I am using name as the form item name in this script.

#Form that sends input to mail using blat
#!/perl5/bin/perl

use URI::Escape;

#output http headers
print "Content-type: text/html\n\n";

#define mail program and recipient address
$send_to = "person\@location.com";
$mail_prog = "blat.exe";

#Make sure the CGI request comes from the form
if ($ENV{'REQUEST_METHOD' } eq "GET" ) {
        $buffer = $ENV{'QUERY_STRING'};
        if($buffer eq "")  {
          print "<TITLE>Error</TITLE>\n";
          print "<H1 align=center>No</H1>\n";
          print "Use the form boxes.\n";
          exit(1);
        }
   }    else  {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   }

#Parse Env. variables from buffer
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
   ($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%2C/,/g;
$value =~ s/%28/(/g;
$value =~ s/%29/)/g;
$value =~ s/%3F/?/g;
$value =~ s/%3A/:/g;
$value =~ s/%21/!/g;
$value =~ s/%2F/\//g;
$value =~ s/%5C/\\/g;
$value =~ s/%5B/\[/g;
$value =~ s/%5D/\]/g;
$value =~ s/%0D%0A/\n/g;
$value =~ s/%([a-fA-f0-9] [a-fA-f0-9])/pack("C", hex($1))/eg;
  $form{$name} = $value;
}

$variablearray{'date'} = &getdate;
$variablearray{'time'} = &gettime;

#check that all form boxes are filled out
#and all env. variables passed
if($form{"name"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please specify who this is from.</h1>\n";
  exit(1);
}
if($form{"month"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please select a month.</h1>\n";
  exit(1);
}
if($form{"year"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please select a year.</h1>\n";
  exit(1);
}

#format the text of the textarea field
#so it is not all one line when mailed
#$text = ($form{"added"});
#$a = length($text);
#$b = 50;
#$c = 51;
#while ($a > $b)  {
#   $x = index($text," ",$b);
#   substr($text,$x,1) = "\n";
#   $b = $b + $c;
#   $c = $c + 1;
#}

#print the contents of the form fields into a text file
open (OUT, ">escl") || die "Could not open Escl";
print OUT "Date:        $variablearray{'date'}\n";
print OUT "\n";
print OUT "Time:        $variablearray{'time'}\n";
print OUT "\n";
print OUT "To:          $form{'to'}\n";
print OUT "\n";

$name = uri_unescape($name);
print OUT "From:        $name\n";
forgot to mention I get server error during submission

TIA
replace the foreach loop with

foreach $pair (@pairs)  {
          ($name, $value) = split(/=/, $pair);
          $form{$name} = uri_unescape($value);
}

then, at the bottom, use

print OUT "From: $form{email}\n";

If you're getting a server error, though, it's somewhat likely you don't have the URI::Escape package installed.  If that's the case, either install it, or, leave the foreach loop as it is, but change

$value =~ s/%29/)/g;
$value =~ s/%3F/?/g;

to

$value =~ s/%29/)/g;
$value =~ s/%40/\@/g;
$value =~ s/%3F/?/g;

the value =~ .... thing hit it right on the head  thanks