Hi,
I have a simple perl question. I'm new to this so don't laugh. How do I input a feild from the URL into the script. Here is what I mean:
<!-- m --><a class="postlink" href="http://whatever.com/test.cgi?name=FEILD">http://whatever.com/test.cgi?name=FEILD</a><!-- m --> HERE
and it would print this into the script:
$name="FEILD HERE";
print "Category/$name"\n;
Any help would be greatly appreciated.
Thank You,
Pawel KowalskiEven though you are passing the name/value pair in the URL instead of in the form, it is still a name/value pair, you must parse the data being sent, since the data passed in the URL is via the GET method make sure your parsing routine has a get method option. Something like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { 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;
}
Avoid spaces in the name/value pairs sent via the URL. Use NAME_FIELD instead of NAME FIELD.
Somewhere in your script you would use (assuming above parsing code):
print "Category/$FORM{'name'}"\n;
HTH,
KevinHi,
Thank you so much. I am learing perl as we speak and was wondering if you knew a place I could find out what the statements in the script you gave me meant, or maybe someone in this forum has the time to help me out and explain it to me. I'd be greatful. Again thank you for the help this will help me out a lot.
PaulYou could start here: <!-- m --><a class="postlink" href="http://www.perlaccess.com/">http://www.perlaccess.com/</a><!-- m -->
and do a search on google or other search engine for "Perl Tutorials" and you will find dozens of online resources.
Regards,
KevinHere is what I got and it didn't work. It just prints Category/ and doesn't put the feild this. Here is my script:
#!/usr/bin/perl
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'};
}
else { 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;
}
print "Content-type: text/html\n\n";
print "Category/$FORM{'name'}\n";
Can some one help me out. Also here is the URL I'm inserting:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/test.cgi?name=FEILD">http://www.fanaticnetwork.com/cgi-bin/t ... name=FEILD</a><!-- m -->
Thank You,
PaulAdd this line into the parsing routine and see if it helps:
$FORM{$name} = $value;
so it looks like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { 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;
}
Regards,
KevinThank you Kevin, it works now.
PaulHi,
well I'm learning this whole CGI stuff. About the above code, how can I insert multiple feilds. For instance:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi?URL=http://www.thehotweb.net&name=Paul">http://www.fanaticnetwork.com/cgi-bin/n ... &name=Paul</a><!-- m -->
I tried a few things and none work.
Thanks,
PaulI'm not exactly sure what you mean, but I'm assuming you wish to send multiple name/value pairs with the URL. This follows a very basic syntax:
first the URL:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi">http://www.fanaticnetwork.com/cgi-bin/name.cgi</a><!-- m -->
then a question mark to indicate there is extra data being sent with the URL:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi">http://www.fanaticnetwork.com/cgi-bin/name.cgi</a><!-- m -->?
then the name/value pairs seperated by an & sign if there is more than one:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi?name=Paul&type=admin&action=go">http://www.fanaticnetwork.com/cgi-bin/n ... &action=go</a><!-- m -->
each name/value pair should have a unique name, although it should be possible to send multiple values for the same name but you would need to modify the parsing routine.
Regards,
KevinYep that's what I mean. So would the code look like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $URL, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
$FORM{$URL} = $value;
}or mebe u could try this .. but don' ask why .. coz i have no idea 'bout it ...
use CGI;
$input = new CGI;
$Name = $input->param('Name');
$Desc = $input->param('Desc');
$URL = $input->param('URL');
& u could access it like ..
<!-- m --><a class="postlink" href="http://www.somethin.com/trial.pl?Name=qwprince&Desc=dumb&URL=http://www.qwprince.com">http://www.somethin.com/trial.pl?Name=q ... prince.com</a><!-- m -->
and yeah it does work anyway .. coz i have used it ..
hope this is what u wanted ..That's if you have the CGI.pm module installed.still as far as i see it works on any pc having activeperl + most of the free cgi webservers ..Thanks for the code. Will this work with a form though. I will be using a form to get user submissions and then this will send it to many search engines.
Thanks,
Paul
Originally posted by qwprince
or mebe u could try this .. but don' ask why .. coz i have no idea 'bout it ...
use CGI;
$input = new CGI;
$Name = $input->param('Name');
$Desc = $input->param('Desc');
$URL = $input->param('URL');
& u could access it like ..
<!-- m --><a class="postlink" href="http://www.somethin.com/trial.pl?Name=qwprince&Desc=dumb&URL=http://www.qwprince.com">http://www.somethin.com/trial.pl?Name=q ... prince.com</a><!-- m -->
and yeah it does work anyway .. coz i have used it ..
hope this is what u wanted ..Hi Paul,
The parsing code I posted in the post on 07-01-2001 08:02 PM will work fine for what you are trying to do.
Remember, each name/value pair you send with the URL is exactly the same as if they were seperate input fields coming from a form. You don't need to put this line in the code:
$FORM{$URL} = $value
and in fact you shouldn't, it may confuse the script.
this line:
$FORM{$name} = $value
is already assigning the value of each name that is sent to the script.
Using the parsing script I posted you should be able to print the results to verify the values of the name/value pairs being sent with the URL:
print "URL = $FORM{'URL'}<br>";
print "name = $FORM{'name'}";
Regards,
KevinThanks Kevin works now.yep it does work with forms..
#!C:/Perl/Bin/Perl
use CGI;
$input = new CGI;
$Fname = $input->param('Fname');
$Mname = $input->param('Mname');
$Lname = $input->param('Lname');
print "Content-type: text/html\n\n";
print "Your name is: <font face=verdana,arial size=2 color=black>" . $Fname . " ";
print "" . $Mname . " ";
print "" . $Lname . "</font>";
=======>>>THE HTML FORM
<form method=post name=search action="cgi-bin/temp.cgi">
<font face=verdana,arial size=2 color=black>
First Name : <input name="Fname" size="20" maxlength="30"><br>
Middle Name :<input name="Mname" size="20" maxlength="30"><br>
Last Name : <input name="Lname" size="20" maxlength="30"><br></font>
<input type=SUBMIT value="Enter Data" name="SUBMIT">
</form>
I have a simple perl question. I'm new to this so don't laugh. How do I input a feild from the URL into the script. Here is what I mean:
<!-- m --><a class="postlink" href="http://whatever.com/test.cgi?name=FEILD">http://whatever.com/test.cgi?name=FEILD</a><!-- m --> HERE
and it would print this into the script:
$name="FEILD HERE";
print "Category/$name"\n;
Any help would be greatly appreciated.
Thank You,
Pawel KowalskiEven though you are passing the name/value pair in the URL instead of in the form, it is still a name/value pair, you must parse the data being sent, since the data passed in the URL is via the GET method make sure your parsing routine has a get method option. Something like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { 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;
}
Avoid spaces in the name/value pairs sent via the URL. Use NAME_FIELD instead of NAME FIELD.
Somewhere in your script you would use (assuming above parsing code):
print "Category/$FORM{'name'}"\n;
HTH,
KevinHi,
Thank you so much. I am learing perl as we speak and was wondering if you knew a place I could find out what the statements in the script you gave me meant, or maybe someone in this forum has the time to help me out and explain it to me. I'd be greatful. Again thank you for the help this will help me out a lot.
PaulYou could start here: <!-- m --><a class="postlink" href="http://www.perlaccess.com/">http://www.perlaccess.com/</a><!-- m -->
and do a search on google or other search engine for "Perl Tutorials" and you will find dozens of online resources.
Regards,
KevinHere is what I got and it didn't work. It just prints Category/ and doesn't put the feild this. Here is my script:
#!/usr/bin/perl
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'};
}
else { 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;
}
print "Content-type: text/html\n\n";
print "Category/$FORM{'name'}\n";
Can some one help me out. Also here is the URL I'm inserting:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/test.cgi?name=FEILD">http://www.fanaticnetwork.com/cgi-bin/t ... name=FEILD</a><!-- m -->
Thank You,
PaulAdd this line into the parsing routine and see if it helps:
$FORM{$name} = $value;
so it looks like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { 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;
}
Regards,
KevinThank you Kevin, it works now.
PaulHi,
well I'm learning this whole CGI stuff. About the above code, how can I insert multiple feilds. For instance:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi?URL=http://www.thehotweb.net&name=Paul">http://www.fanaticnetwork.com/cgi-bin/n ... &name=Paul</a><!-- m -->
I tried a few things and none work.
Thanks,
PaulI'm not exactly sure what you mean, but I'm assuming you wish to send multiple name/value pairs with the URL. This follows a very basic syntax:
first the URL:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi">http://www.fanaticnetwork.com/cgi-bin/name.cgi</a><!-- m -->
then a question mark to indicate there is extra data being sent with the URL:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi">http://www.fanaticnetwork.com/cgi-bin/name.cgi</a><!-- m -->?
then the name/value pairs seperated by an & sign if there is more than one:
<!-- m --><a class="postlink" href="http://www.fanaticnetwork.com/cgi-bin/name.cgi?name=Paul&type=admin&action=go">http://www.fanaticnetwork.com/cgi-bin/n ... &action=go</a><!-- m -->
each name/value pair should have a unique name, although it should be possible to send multiple values for the same name but you would need to modify the parsing routine.
Regards,
KevinYep that's what I mean. So would the code look like this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $URL, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
$FORM{$URL} = $value;
}or mebe u could try this .. but don' ask why .. coz i have no idea 'bout it ...
use CGI;
$input = new CGI;
$Name = $input->param('Name');
$Desc = $input->param('Desc');
$URL = $input->param('URL');
& u could access it like ..
<!-- m --><a class="postlink" href="http://www.somethin.com/trial.pl?Name=qwprince&Desc=dumb&URL=http://www.qwprince.com">http://www.somethin.com/trial.pl?Name=q ... prince.com</a><!-- m -->
and yeah it does work anyway .. coz i have used it ..
hope this is what u wanted ..That's if you have the CGI.pm module installed.still as far as i see it works on any pc having activeperl + most of the free cgi webservers ..Thanks for the code. Will this work with a form though. I will be using a form to get user submissions and then this will send it to many search engines.
Thanks,
Paul
Originally posted by qwprince
or mebe u could try this .. but don' ask why .. coz i have no idea 'bout it ...
use CGI;
$input = new CGI;
$Name = $input->param('Name');
$Desc = $input->param('Desc');
$URL = $input->param('URL');
& u could access it like ..
<!-- m --><a class="postlink" href="http://www.somethin.com/trial.pl?Name=qwprince&Desc=dumb&URL=http://www.qwprince.com">http://www.somethin.com/trial.pl?Name=q ... prince.com</a><!-- m -->
and yeah it does work anyway .. coz i have used it ..
hope this is what u wanted ..Hi Paul,
The parsing code I posted in the post on 07-01-2001 08:02 PM will work fine for what you are trying to do.
Remember, each name/value pair you send with the URL is exactly the same as if they were seperate input fields coming from a form. You don't need to put this line in the code:
$FORM{$URL} = $value
and in fact you shouldn't, it may confuse the script.
this line:
$FORM{$name} = $value
is already assigning the value of each name that is sent to the script.
Using the parsing script I posted you should be able to print the results to verify the values of the name/value pairs being sent with the URL:
print "URL = $FORM{'URL'}<br>";
print "name = $FORM{'name'}";
Regards,
KevinThanks Kevin works now.yep it does work with forms..
#!C:/Perl/Bin/Perl
use CGI;
$input = new CGI;
$Fname = $input->param('Fname');
$Mname = $input->param('Mname');
$Lname = $input->param('Lname');
print "Content-type: text/html\n\n";
print "Your name is: <font face=verdana,arial size=2 color=black>" . $Fname . " ";
print "" . $Mname . " ";
print "" . $Lname . "</font>";
=======>>>THE HTML FORM
<form method=post name=search action="cgi-bin/temp.cgi">
<font face=verdana,arial size=2 color=black>
First Name : <input name="Fname" size="20" maxlength="30"><br>
Middle Name :<input name="Mname" size="20" maxlength="30"><br>
Last Name : <input name="Lname" size="20" maxlength="30"><br></font>
<input type=SUBMIT value="Enter Data" name="SUBMIT">
</form>