in reply to making a difference between POST parameters and URL parameters

The CGI module deliberately makes a unified interface so that you can do:
if (defined ($q->param('foo')) { print "foo is defined!\n"; print "foo = ", $q->param('foo'), "\n"; }

regardless of the means by which the parameters were generated.

Well formed HTML forms either specify a method of POST _or_ GET, not both. Doing both is supported by CGI, but only because the CGI developers are kind to web developers, not because it's an actual part of the CGI standard. More explicitly, you shouldn't generally care which method is used.

If you can provide more information about your problem and what you're trying to accomplish, other monks might be able to help you solve the real issue, as opposed to processing GET and POST simultaneously

  • Comment on Re: making a difference between POST parameters and URL parameters
  • Download Code

Replies are listed 'Best First'.
Re^2: making a difference between POST parameters and URL parameters
by moritz (Cardinal) on Feb 14, 2008 at 16:21 UTC
    Well formed HTML forms either specify a method of POST _or_ GET, not both.

    That's right, but you can use an html that has "post" as the request method to an URL that contains URL params, and the w3c spec doesn't recommend against it.

    (Or is that anywhere else, and I just haven't found it?)

Re^2: making a difference between POST parameters and URL parameters
by olus (Curate) on Feb 14, 2008 at 16:30 UTC

    Doing both is supported by CGI, but only because the CGI developers are kind to web developers, not because it's an actual part of the CGI standard.

    Actually, both are in the standard. See here

    update: misunderstood the quoted line. I was trying to say that both methods are in the standard, not the usage of both simultaneously.

      Hmmm ... I wonder if Doing both is more about CGI possibly processing *both* URL params and STDIN params for a POST? One of the best comments in cpan:

      if ($meth eq 'POST') { $self->read_from_client(\$query_string,$content_length,0) if $content_length > 0; # Some people want to have their cake and eat it too! # Uncomment this line to have the contents of the query string # APPENDED to the POST data. # $query_string .= (length($query_string) ? '&' : '') . $ENV{'QUERY_ +STRING'} if defined $ENV{'QUERY_STRING'}; last METHOD; }
      ... I like cake.

      -derby
        ...but doesn't Fletch keep telling us that the cake is a lie?

        ...roboticus

        /me has tongue firmly planted in cheek

        Well, if it's a POST query, param() will only get you POST params.

        You can get GET params by instancing another CGI object like this:

        my $get = CGI->new($ENV{'QUERY_STRING'});

        Example:

        use strict; use warnings "all"; use CGI; my $post= CGI->new; my $get = CGI->new($ENV{'QUERY_STRING'}); my $foo_from_post = $post->param('foo'); my $foo_from_get = $get->param('foo');