elusion has asked for the wisdom of the Perl Monks concerning the following question:

My Fellow monks,

When I am writing a CGI of some sort and have need for a POST method, I like to put a location param in the action value of the form so it can be seen in the page location. However, CGI.pm reads variables from POST xor GET, so I cannot get the added params in this fashion.

My question is, why does it do this? Is it to save time or is there some kind of security hazard?

elusion : http://matt.diephouse.com

  • Comment on Why does CGI.pm's param check GET xor POST?

Replies are listed 'Best First'.
Re: Why does CGI.pm's param check GET xor POST?
by danboo (Beadle) on Apr 05, 2002 at 16:31 UTC
    Why? I'm not sure... but you should be able to get the URL parameter. From 'perldoc CGI', section 'MIXING POST AND URL PARAMETERS':
    To retrieve URL parameters, call the url_param() method.
    Cheers,

    - danboo

Re: Why does CGI.pm's param check GET xor POST?
by swiftone (Curate) on Apr 05, 2002 at 17:31 UTC
    From CGI.pm (v2.80, line 455 or so)
    # 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{'QUER +Y_STRING'} if defined $ENV{'QUERY_STRING'};
    So if you're willing to change CGI.pm every upgrade, there you go. Why it's done I'm afraid I don't know.
Re: Why does CGI.pm's param check GET xor POST?
by wardk (Deacon) on Apr 05, 2002 at 16:30 UTC
    If I understand correctly, it sounds like you are doing:
    <form method="post" action="/cgi-bin/myScript?location=value">
    and by doing so, you have no access to location parm via:
    my $location = param('location');
    If this is the case, I would suggest you use a hidden parameter ala:
    <form method="post" action="/cgi-bin/myScript"> <input type="hidden" name="location" value="val">
    you can then access the location value via the param call.

    UPDATE: in re-reading, it appears that you are wanting the form var to appear in the browser location field for a POSTed form. If this is the case, then I am not sure there is a solution

      I realize that I can access it using a hidden form parameter, but I like to put it in the action value so that it is viewable in the browser. This way when a user bookmarks it, or something like that, it bookmarks that page and not the main page.

      elusion : http://matt.diephouse.com

Re: Why does CGI.pm's param check GET xor POST?
by belg4mit (Prior) on Apr 05, 2002 at 20:28 UTC
    Other things to consider:
  • using PATH_INFO
  • parsing(using's CGI's internal methods) SCRIPT_NAME or URI_REQUEST
  • --
    perl -pe "s/\b;([st])/'\1/mg"

      To expand a little on the suggestion above, PATH_INFO is added like this:
      # url my.domain.com/cgi-bin/script.cgi # url with path info my.domain.com/cgi-bin/script.cgi/path_info_here
      The path info is then available in $ENV{'PATH_INFO'}

      .02

      cLive ;-)

(crazyinsomniac) Re: Why does CGI.pm's param check GET xor POST?
by crazyinsomniac (Prior) on Apr 07, 2002 at 12:42 UTC