Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new to perl : pass value from form to perl script

Status
Not open for further replies.

vbkal

Programmer
Jan 30, 2002
13
BE
Hello,

I don't know if I am posting this question to the right forum, excuse me if I am :

I have the following

1/ html file
<html>
<body>
<form method="post" action="test.pl">
<input type="hidden" name="hiddenfield" value="abc">
<input type="submit" value="TEST">
</form>
</body>
</html>

2/ perl script
#!/usr/bin/perl
use CGI qw:)standard);
print "Content-type:text/html\n\n";

my $FormData;
# Read the standard input (sent by the form):

read(STDIN, $FormData, $ENV{"CONTENT_LENGTH"});
# Get the name and value for each form input:
@pairs = split(/&/, $FormData);
# Then for each name/value pair....
foreach $pair (@pairs) {
# Separate the name and value:
($name, $value) = split(/=/, $pair);
# Convert + signs to spaces:
$value =~ tr/+/ /;
# Convert hex pairs (%HH) to ASCII characters:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Store values in a hash called %FORM:
$FORM{$name} = $value;
}

print "The following text was entered in the e text field: $FORM{'textfield'}";
print "The hidden text is: $FORM{'hiddenfield'}";

My variable doesn't get passed to the perl script? Running the perl script is no problem, but no variable?
I think the error is of trying to run this on my local PC (but that's the goal of my script!)
Is there another way to start a local perl script with variables from a local htm file?

thx,
vbkal
 
Code:
#!/usr/bin/perl
use CGI qw(:standard);
$q=new CGI;
#print "Content-type:text/html\n\n";
print $q->header;
$hidden=$q->param('hiddenfield');
#you mention a textfield which isn't in your HTML form
print $q->start_html(-title=>"My form displaying $hidden");
print $q->"The hidden text is: $hidden";

You should look up Lincoln D Stein's pages at cshl.org, for more example on using the CGI module

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
Paul,

This still doesn't work. It prints "The hidden text is : ".
My parameter doesn't get passed to the perl script.

???
vbkal
 
Hi,

Just to make sure, you are running a web server on your PC aren't you?

Don't want to sound condesending but you do say you are new to perl, Pauls code should work fine if ran in the proper environment.

A few things lead me to believe this could be the problem;

Running the perl script is no problem
and
<form method="post" action="test.pl">

First off you don't need to 'run' the perl code as it should be called from your html.

Secondly, it is bad practice to have scripts running in the same directory as the flat html files and I don't know of a server that has an initial set up like this.

Apologies to you if I'm way off track but I thought this might help.

Sim



----------------------------------------
I was once asked if I was ignorant or just apathetic. I said, "I don't know, and I don't care."
----------------------------------------
 
Hi Sim,

Thank you for your answer.
You weren't way off track. That's what I wanted to know : you do need a web server on your pc before you can achieve this kind of interaction between a html page and a perl script.

This is my goal :
let's say a network of 5 people. Each have the same directory with a few text files, one perl script and a htm page. From a textfile and a button on this htm page they should be able to activate a local perl script on their pc (so they do not have a web server on their pc) which alters the choosen text file.
I thought I could do this by passing a value from the htm page to the perl script, but obviously I was wrong.

I must now look for another solution.
thank you for your answer,
vbkal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top