View Full Version : HTML output w/ variable! please help!
sekritagentgirl
04-09-2003, 07:17 PM
Hi, I'm trying to incorporate a "preview" so to speak in my mail form.
A user will fill in their info into a form and click "Next"... then the values read in will be mailed to me. I got that down fine... but instead of taking them to a "thank you" page, I need the script to output their info in html... but I tried it and it leaves out the variables.
if it's not input thru a form, but rather declared in the beginning ($Variable='some predefined value here'), it works all right.... I can't figure out why it won't work if I declare the variable as $Variable=in{'FieldName'};
The method I used was:
print "Content-type: text/html\n\n";
print <<ENDHTML;
<HTML>
<HEAD>
<TITLE>test</TITLE>
</HEAD>
<BODY>
you entered the word: $Variable.
</BODY>
</HTML>
ENDHTML
Someone please help me! Thanks!
ACJavascript
04-10-2003, 01:20 AM
It sounds like you arn't parsing the forms before you try to show them,, Try this
-------
Put after your location to perl
-------
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;
$FORM{$name} = $value;
}
##THen declare the forms like so
print "Content-type: text/html\n\n";
print <<ENDHTML;
<HTML>
<HEAD>
<TITLE>test</TITLE>
</HEAD>
<BODY>
you entered the word: $FORM{'usersName'}
</BODY>
</HTML>
ENDHTML
---------------------------
Now the form were the user rights in there data..
<form action="ScriptsName.cgi" method="POST">
<input type="text" name="usersName" value="Your Name">
<input type="submit" value="GO">
</form>
Hope it helps :D
sekritagentgirl
04-10-2003, 07:47 PM
sigh. I tried that. so I thought maybe I made a typo and I pasted exactly what you had but it does exactly what happens without parsing... It just prints the html, and normal text but leaves out the variables. :( so, it prints:
You entered the word:
just like that.
ACJavascript
04-10-2003, 08:33 PM
In the form action do you have
method="POST"
would look like this
<form action="script.cgi" method="POST">
sekritagentgirl
04-11-2003, 02:31 AM
yup.. :confused:
ACJavascript
04-11-2003, 04:26 PM
mmmm,, very interesting..
Can you post your script here? so We can see this illusive problem hehe :D
sekritagentgirl
04-11-2003, 07:20 PM
I tried your code ans that didn't work... did the same thing as my code:
#!/usr/bin/perl -w
$variable='Name';
print "Content-type: text/html\n\n";
print <<ENDHTML;
<HTML>
<HEAD>
<TITLE>test</TITLE>
</HEAD>
<BODY>
Your name: $variable
</BODY>
</HTML>
ENDHTML
exit;
check this out: http://www.pageresource.com/cgirec/ptut5.htm
that works, but it's declaring the variable's value in the code... but i can't get it to let me read it in from the form instead... I dunno why... your code did the same thing even when parsing the forms
ACJavascript
04-11-2003, 07:52 PM
mmm,,, Okay try this,,.
First make the html page as this.
<form action="test.cgi" method="POST">
Your Email Address: <input type="text" name="user" value="">
<input type="submit" value="GO">
</form>
-----------
Now make this script test.cgi
++++++++++
#!/usr/bin/perl
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;
$FORM{$name} = $value;
}
print "Content-type:text/html\n\n";
print "Your Email address is $FORM{'user'}\n";
exit;
sekritagentgirl
04-11-2003, 09:14 PM
sigh. that works. lol. thanx. i just thought i'd be able to use the endhtml deal so that i could avoid escaping some characters like '/' and such... cus i'm going to be using a crapload of tables and it'll be sort of annoying... but oh well. i guess i have no choice! thanks for your help! :thumbsup:
ACJavascript
04-11-2003, 09:19 PM
mmmm,, Well before you go through that table thingy hehe,, (nasty:D)
try this instead of print"";
---
print "Content-type:text/html\n\n";
print <<EOF;
Your Email address is $FORM{'user'}
EOF
exit;
------
sekritagentgirl
04-13-2003, 05:16 AM
wow, that worked perfect!! thanks a lot! I really appreciate all your help. thanks so much again!! :D
ACJavascript
04-13-2003, 05:32 PM
Hey no problem :D
Enjoy!!! :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.