Solved

error in data

Posted on 1999-01-04
9
127 Views
Last Modified: 2010-03-05
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 ?
0
Comment
Question by:craigs052998
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 70 total points
ID: 1207293
It's being escaped for safety... you need to unescape it.  If the variable name is $address

use URI::Escape;

$address = uri_unescape($address);

0
 

Author Comment

by:craigs052998
ID: 1207294
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 ?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207295
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:craigs052998
ID: 1207296
that didn't work.  I got    uri_unescape(subject) in my from box with the following code:

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

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207297
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";


0
 

Author Comment

by:craigs052998
ID: 1207298
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";
0
 

Author Comment

by:craigs052998
ID: 1207299
forgot to mention I get server error during submission

TIA
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207300
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;

0
 

Author Comment

by:craigs052998
ID: 1207301
the value =~ .... thing hit it right on the head  thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question