Click to See Complete Forum and Search --> : mail address is rewritting itself
chrisbot
11-19-2005, 12:00 AM
I need some help !! I am working on a site where I have an application process. It is very simple or should be. An HTML form submits to a perl CGI so far so good. This cgi creates another page on which is another html form ! In this form is a hidden input field with the my mailing address. This is submitted and is processed so as the data is sent to me via an email. What is happening is although I write the mail address
mail@yogamaroc.com
What comes out in the source of the final page is
mail.com
This is also happening on the html of the page itself where I have a mailto link.
It seems like the @ is doing somthing. Maybe because it is a form in a form I dunno. Can anyone she light on this??
Chrisbot
Jeff Mott
11-19-2005, 09:13 AM
The @ symbol denotes an array. And you probably use double quotes in all your print statements, which attempt to interpolate variables. So perl tries to interpolate the array @yogamaroc (which I assume is empty) for that portion of the address.
You could simply escape the @ symbol with a backslash, or you could use a kind of quotation that does not do interpolation. Perl has many ways to allow you to quote text. Take a look at Quote and Quote-like Operators (http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators) in the Perl manual for information on how to use them all.
chrisbot
11-28-2005, 05:49 PM
Thanks Jeff
I actually slept on it and woke up with the answer in my head. Put a backslash in and it worked. Just found your answer, thank.
Have another prob now. Have been working on an online application. This is the prob.
Html file submits 3 variables to pl cgi. There variables are used to generate a page specific to the variables and returns this to the browser.
On that page are a couple of paypal buttons which direct the browser to paypal. What I want is for the browser to return to the page it left, only when this happens it has lost the variables so will not render.
To sort this I made the script write the variables as cookies, and then pick them up again, so as you can re-enter the page. This works seemlessly on Safari, but just tested it on IE and bugger me it wont work. What is up with Microsoft????
#!/usr/bin/perl
if ($ENV{'HTTP_COOKIE'})
{ @cookies=split(/; /,$ENV{'HTTP_COOKIE'}) };
foreach $item(@cookies)
{ ($key,$content) = split(/=/,$item,2);
$fields{$key}=$content;
}
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}
# SAVE VARIABLES IN COOKIES
print "Set-Cookie:course = $fields{course} ;
expires = Thu, 01-Dec-2006 00:00:00 GMT\n";
print "Set-Cookie:method = $fields{method} ;
expires = Thu, 01-Dec-2006 00:00:00 GMT\n";
print "Set-Cookie:currency = $fields{currency};
expires = Thu, 01-Dec-2006 00:00:00 GMT\n";
# VARIABLES
$d = $fields{course};
$m = $fields{method};
$c = $fields{currency};
this is my script, what can I do to get IE to behave???
Chris
Jeff Mott
11-28-2005, 07:38 PM
Can you put a text file of the full source online as well as a working example? All the Perl scripting happens on the server-side so there should be no difference regardless of the browser.
As a side note, the CGI module has been the standard way of parsing CGI parameters and cookies ever since perl4 was replaced by perl5, and it's a good idea to use it here. The hand written ways are almost always less secure and potentially buggy. (It's possible that's what's happening here. The spaces before and after the equal sign and semi-colons may be causing problems.) There is a sticky thread called "Learn Perl and CGI with 'Beginning Perl'". Reading through the text recommended there could help you learn the currently standard ways of performing these common, yet deceptably tricky jobs.
chrisbot
11-28-2005, 08:30 PM
http://yogamaroc.com/yogamaroc2006/english/application.html
This is the html page which loads to my perl script.
use Ie and have a go.
After the first page, submit. A page with 4 circles appears. Click on the second circle for forms. The window opens, then after a while the parent page refreshes and disapears.
Yes I was surprised by this because as you say the whole thing is on server side and ought not be effected by which browser it hits. But it IS. which has pissed me off. Not a great fan of IE and now it has come back to haunt me.
Thanks for your support Jeff
cxx :)
Nedals
11-30-2005, 02:05 AM
When I click on 'continue' (submit)... In Firefox I get the source code back and in IE I get a 'page error' message I've never seen before.
At a guess I would say you forgot the send the header...
print $q->header(); ## OO mode of CGI
chrisbot
11-30-2005, 08:53 PM
Nedals
Hi, yes I have sorted everything now with regard IE, only Netscape and FireFox are rendering my Perl script as code and not as they should.
I think it is my MIME header, but I am using the Perl
{print << "DOC";
To pring my HTML document. There is an HTML Content-Type header in the HTML script, but this is rendering as code too as you noticed.
What is the answer. How can I correctly use Perl to set the mime type for Netscape and FireFox to pick up?? Can I use the
{print << "DOC";
method or will I have to re-write the page with every line as
print ""
If I can CRACk this I will be a happy man
xxxx
chrisbot
Jeff Mott
12-01-2005, 01:01 PM
Have you sorted this out on your own now? Everything seems fine browsing with FF (except that one of the continue buttons was cutoff on one of the pages; too far down for the size of the window).
Normally, however, it is considered a good practice to use the CGI module for the header and HTML generation.
Nedals
12-02-2005, 02:02 PM
Looking at your code, I'm a little confused at to what is comming from where!!
You are first reading 'course', 'method', and 'currency' cookies, setting a %field hash. You then read the SAME items from a HTML <form> resetting those values. What are you trying to do?
As Jeff mentioned, you should really be using the CGI module that comes standard with most Perl installations. You should also be using 'strict'
#!/usr/bin/perl
use strict;
use CGI;
my $q = CGI->new(); ## Gets an instance of CGI. (this is what I use, there are other methods)
## To read a cookie...
my $course_cookie = $q->cookie('course');
## To read a form item...
my $d = $q->param('course');
## To output a page, setting a cookie
my $cookie = "course=$d; expires=Thu, 01-Dec-2006 00:00:00 GMT";
print $q->header(-cookie=>$cookie);
print <<DOC;
..
the HTML page
..
DOC
# or multipule cookies...
print $q->header(-cookie=>[$cookie1,$cookie2,etc]);