Gossamer Forum
Home : General : Perl Programming :

Need Help, passing the input query from Form

Quote Reply
Need Help, passing the input query from Form
Hi,

I need to print the query from the form using a simple script back as a link.

Here is what I have so far.

#!/usr/bin/perl

# Parse User Input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}

&Content;

sub Content {
$query = $FORM{'query'};
$query =~ tr/ /+/;

print <<'EOM';
Content-Type: text/html
<html>
<head>
<A target="_blank" href="http://www.site.com/cgi-bin/data.pl?$query">query</A>
</body>
</html>
EOM
}

Here is the input form:

<form action="/cgi-bin/links.pl" method="POST">
<table width="300" border="0" cellspacing="0" cellpadding="3">
<caption align="top"><h2>Quick Links</h2></caption>
<tr>
<td>

<input type="text" name="query"><input
type="submit" value=" Go! "></center>

I do not know how to pass the "query" from the form to this link above.
I am able print it back as a simple print " " statement.
But I would like to avoid using a number of print statements as I can cut and paste my links within the EOM.

Can you help?

Thanks in advance

[This message has been edited by socrates (edited May 31, 1999).]

[This message has been edited by socrates (edited May 31, 1999).]
Quote Reply
Re: Need Help, passing the input query from Form In reply to
You should be able to access any of your form elements using $FORM{'element_name'} in &Content.

Cheers,

Alex
Quote Reply
Re: Need Help, passing the input query from Form In reply to
Thanks for your reply. I don't know why it wouldn't work. I don't know anything about perl.

It is working now, since I am using

sub Header {

print <<'EOM';
Content-Type: text/html

<html>
<head>

blahh....

EOM
}

sub Content {

print qq~
My Content
~;
}

I have no idea why it would not work before. But it works fine now.


Here is a question I have. I want to supply the input to the $query via the command line instead of the form. How do I do it?

I tried:
script.pl?query=whatever

Does not seem to work. Any help would be greatly appreciated. How do activate it to print back without activating it via the form?

Thank You.
Quote Reply
Re: Need Help, passing the input query from Form In reply to
You should use the CGI.pm module, it has built in command line debugging. So you would do:

[em]script.pl[/em]
(offline mode: enter name=value pairs on standard input)
[em]query=whatever[/em]
[em]<ctrl>-D[/em]

and the script would run as if you had passed in query=whatever.

Cheers,

Alex
Quote Reply
Re: Need Help, passing the input query from Form In reply to
Alex,

Thanks. I am now parsing the query both from form input and from command line and it is working fine.