0

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.

5
  • I can't see an issue with the code (although it would be better to print a valid HTML document). What is the error you're getting? What are you trying to fix it? Why are you stuck? Commented Nov 25, 2014 at 7:30
  • I'm not getting the parameters and values. output expected: name5 name6 name7 name8, value5 value6 value7 value8 Commented Nov 25, 2014 at 7:32
  • Have you look at the apache error log? Commented Nov 25, 2014 at 8:36
  • 1
    I have changed from $query->param to $query->url_param. Now it is working fine. Commented Nov 25, 2014 at 8:45
  • my $query ->new CGI - this doesn't look right. I hope you mean my $query = CGI->new. If you don't cut and paste your exact code then it's harder for us to help you. Commented Nov 25, 2014 at 12:16

2 Answers 2

1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

This is a code-only answer. You should explain in a few words how your answer solves the problem.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.