Vasanth
Vasanth

Reputation: 365

Pass values and parameters from HTML to CGI

I am using post method in html to pass the parameters and values to cgi file. From that cgi file I'm extracting the values and parameters. I have tried the code below,

HTML:

    <form action="http://hostname.com/manipulation.cgi?name5=value5&name6=value6&name7=value7&name8=value8" method="POST"> </form>

CGI: manipulation.cgi

use strict;
use CGI;
my $query ->new CGI;
print $query->header();

my @paramNames = $query->param; #Receive N number of parameters
my @paramValues = map $query->param($_), $query->param; #Receive N number of parameters values
print $query->h4("@paramNames,@paramValues");

But I'm not able to get the expected output.

Please help me on this.

Thanks in advance.

Upvotes: 0

Views: 1234

Answers (2)

Dave Cross
Dave Cross

Reputation: 69224

What you are doing makes no sense. If all of your parameters are in the URL, then why are you using POST, not GET? In fact, why are you using a form at all?

If you are using GET then param will give you the parameters from the URL.

If you are using POST then param will give you the parameters from the HTTP request body and url_param will give you the parameters from the URL.

So it seems that you need to switch to using url_param.

It's worth pointing out that learning CGI in 2014 is a bit like learning to use a typewriter. It will work, and some of the skills will be useful. But you'd be far better advised to learn something a little more up to date.

Upvotes: 0

Vasanth
Vasanth

Reputation: 365

url_param — get a parameter from the URL.

use strict;
use CGI;
my $query ->new CGI;
print $query->header();

my @paramNames = $query->url_param; #Receive N number of parameters
my @paramValues = map $query->url_param($_), $query->url_param; #Receive N number of parameters values
print $query->h4("@paramNames,@paramValues");

Upvotes: 1

Related Questions