Question

I have switch-structure on my site.
I work with get requests and I load different scripts, depending on what was in the query. There are switch-instruction in script. For example.

Link: site.com/ - printing something like 'press some menu button'

Link: site.com/?mode=users - loading script users.pl

Link: site.com/?mode=address - loading script addreses.pl

Link: site.com/?mode=users&action=add - loading script users.pl and in this script I has another switch which do dif things depending on get-parameter 'action'.

On _/?mode=users&action=add_ I has form. Action in this form is none (action=''), method=post. So when I press 'send' button this page must be just refreshed with post-parameters yet. Right? Right.

The problem: when I press send button index.pl is loading, not same page. Like there are no get-parameters.

I try to print all parameters, which page receiving

@names = $params->param;
print @names;

It's printing post-parameters, which I entered in form, but not printing get-parameters from link. Link is same : /?mode=users&action=add

I tried to print $ENV{'QUERY_STRING'}; - all parameters shown. Both post and get and their names are correct. Whats the problem? $ENV{'HTTP_REQUEST'}; is only 'post' when I send form, but 'get' when I just loading page with form.

Perl can't send both get and post requests? What I have to do?
This is how I work with query string:

$params=new CGI;
$action=$params->param("mode"); # or $action=$params->param("action");

And switch:

use feature 'switch';
for ($action) {
    when ('users') {
       do "./pages/users.pl";
    }

    .... some more 'when'

    default { 
       print 'select something'; 
    }
}
Was it helpful?

Solution 2

I don't really know why it hadn't work, but I found next solution. For example link is /?mode=users&action=add (its a form). I just adding 2 to form:

<input type='hidden' name='mode' value='users'>
<input type='hidden' name='action' value='add'>

OTHER TIPS

Try with out the slash infront of the question mark eg change /?mode=users&action=add to ?mode=users&action=add

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top