CGI oddity

Hi,

I’m trying to use cgi.rb from stdlib, and I have following problem. When I use GET to send data to script,
everything is fine, it’s also fine when I use POST to do this, but I can’t use both in one script.
I.e., if I have URL: http://localhost/cgi-bin/index.rb?page=guestbook, and, I have a form that sends POST data
to it, then variable “page” doesn’t appear in CGI#params hash.
It looks it wouldn’t be hard to hack that in, but maybe there’s another way?

···


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com

I.e., if I have URL: http://localhost/cgi-bin/index.rb?page=guestbook,
and, I have a form that sends POST data
to it, then variable "page" doesn't appear in CGI#params hash.
It looks it wouldn't be hard to hack that in, but maybe there's another
way?

well, if you have a FORM just add an INPUT tag with the type hidden,
something like

<input type=hidden name=page value=guestbook>

and don't use '?page=guestbook'

Guy Decoux

It looks it wouldn’t be hard to hack that in, but maybe there’s
another way?

I’ve had the exact same problem. This is a little part of my solution:

class CGI
def query_parameters
@qp = parse_query_parameters(query_string) if @qp.nil?
@qp
end

 def parse_query_parameters(query_string)
   parsed_params = {}

   query_string.split(/[&;]/).each { |p|
     k, v = p.split('=')
     parsed_params[CGI.unescape(k)] = v.nil? ? nil : CGI.unescape(v)
   }

   return parsed_params
 end

end

Now you should be able to access all the query_parameters from the hash
returned on that method. Regardless of whether the request was POST or
GET. I doesn’t take much effort to include this seemingly with the
original params method, so you don’t have to distinguish between GET
and POST variables.

The full CGI extension I did, which also turns
“person[address][street]” style inputs into hashes (like PHP), is
included in Rails. The upcoming web-application framework that
currently is just the mirage available at http://rails.nextangle.com/
but hopefully soon will be a released reality.

···


David Heinemeier Hansson,
http://www.basecamphq.com/ – Web-based Project Management
http://www.loudthinking.com/ – Broadcasting Brain

I.e., if I have URL: http://localhost/cgi-bin/index.rb?page=guestbook,
and, I have a form that sends POST data
to it, then variable “page” doesn’t appear in CGI#params hash.
It looks it wouldn’t be hard to hack that in, but maybe there’s another
way?

well, if you have a FORM just add an INPUT tag with the type hidden,
something like

and don’t use ‘?page=guestbook’
This was just an example, there could be a lot of other query arguments and I’m not sure
if I want to maintain their lists in each form that’s used through index.rb

···

On Friday 02 April 2004 23:15, ts wrote:

Guy Decoux


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here → postmaster@sco.com

It looks it wouldn’t be hard to hack that in, but maybe there’s
another way?

I’ve had the exact same problem. This is a little part of my solution:

class CGI

end

Now you should be able to access all the query_parameters from the hash
returned on that method. Regardless of whether the request was POST or
GET. I doesn’t take much effort to include this seemingly with the
original params method, so you don’t have to distinguish between GET
and POST variables.
Thanks, I’ll checkout the code and see how can I use it :slight_smile:

The full CGI extension I did, which also turns
“person[address][street]” style inputs into hashes (like PHP), is
Sounds nice

included in Rails. The upcoming web-application framework that
currently is just the mirage available at http://rails.nextangle.com/
but hopefully soon will be a released reality.
He-he, my problem was related to my yet-to-be-released MuraveyWeb project,
it’s a web-framework also :slight_smile:

···

On Friday 02 April 2004 23:43, David Heinemeier Hansson wrote:


David Heinemeier Hansson,
http://www.basecamphq.com/ – Web-based Project Management
http://www.loudthinking.com/ – Broadcasting Brain


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here → postmaster@sco.com