in reply to Re: CGI.pm ignore URL GET query string parameters
in thread CGI.pm ignore URL GET query string parameters

That all pertains to POST methods. If it's a POST the URL query string doesn't (unless $CGI::APPEND_QUERY_STRING is true) get into $cgi->param(), but if it's a GET it does. I'm asking if there is a way to keep GET parameters from populating $cgi->param(). I thought I remembered there being a pragma or something that allowed that, but I'm probably misremembering.

Replies are listed 'Best First'.
Re^3: CGI.pm ignore URL GET query string parameters
by afoken (Chancellor) on Mar 13, 2024 at 20:23 UTC
    if there is a way to keep GET parameters from populating $cgi->param().

    Why? Check the result of request_method() first, then decide on how you want to handle parameters.

    Or, if you really insist on that strange behaviour, inherit from CGI and override param() and multi_param(). Something like this:

    package StrangeCGI; # completely untested! use strict; use warnings; use parent 'CGI'; sub multi_param { my ($sself,@args)=@_; if ($self->request_method() ne 'POST') { return; } else { return $self->SUPER::multi_param(@args); } } sub param { my ($sself,@args)=@_; if ($self->request_method() ne 'POST') { return; } else { return $self->SUPER::param(@args); } } 1;
    I thought I remembered there being a pragma or something that allowed that,

    I don't think that was ever possible.

    but I'm probably misremembering.

    You probably are.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: CGI.pm ignore URL GET query string parameters
by pryrt (Abbot) on Mar 13, 2024 at 20:26 UTC
    I thought I remembered there being a pragma or something that allowed that, but I'm probably misremembering.

    Do you mean the invocation method defined at CGI.pm's Creating-a-new-query-object-from-an-input-file of CGI), which has the example:

    To create an empty query, initialize it from an empty string or hash:
    my $empty_query = CGI->new(""); -or- my $empty_query = CGI->new({});

    This creates your query object without any parameters from the get-go.

    Or, if you want to use the parameters at first so that you can extract information, but then delete them before outputting any HTML so they don't pre-populate forms, then you probably want to read Deleting-all-parameters of CGI to find $q->delete_all(); , which will delete the parameters at your whim.

      "Do you mean the invocation method defined at CGI.pm's Creating-a-new-query-object-from-an-input-file of CGI)"
      No I was wondering about something like use CGI qw( -ignore_get_params ). If that existed it would be a simple way to ignore GET params without having to check $cgi->request_method().
        No I was wondering about something like use CGI qw( -ignore_get_params ). If that existed it would be a simple way to ignore GET params without having to check $cgi->request_method().

        Then no, not as far as I know.

        Why do you want to avoid $cgi->delete_all() if $cgi->request_method() eq 'GET'; ? I cannot see how that's any harder or more confusing than the non-existent use CGI qw( -ignore_get_params ) that you suggested.