CGI oddity

Discussion in 'Ruby' started by Dmitry V. Sabanin, Apr 2, 2004.

  1. 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 ->
     
    Dmitry V. Sabanin, Apr 2, 2004
    #1
    1. Advertising

  2. Dmitry V. Sabanin

    ts Guest

    >>>>> "D" == Dmitry V Sabanin <> writes:

    D> I.e., if I have URL: http://localhost/cgi-bin/index.rb?page=guestbook,
    D> and, I have a form that sends POST data
    D> to it, then variable "page" doesn't appear in CGI#params hash.
    D> It looks it wouldn't be hard to hack that in, but maybe there's another
    D> 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
     
    ts, Apr 2, 2004
    #2
    1. Advertising

  3. On Friday 02 April 2004 23:15, ts wrote:
    > >>>>> "D" == Dmitry V Sabanin <> writes:

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

    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

    >
    > Guy Decoux


    --
    sdmitry -=- Dmitry V. Sabanin
    MuraveyLabs.
    Spam Here ->
     
    Dmitry V. Sabanin, Apr 2, 2004
    #3
  4. > 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
     
    David Heinemeier Hansson, Apr 2, 2004
    #4
  5. On Friday 02 April 2004 23:43, David Heinemeier Hansson wrote:
    > > 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 :)

    > 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 :)

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


    --
    sdmitry -=- Dmitry V. Sabanin
    MuraveyLabs.
    Spam Here ->
     
    Dmitry V. Sabanin, Apr 2, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    539
  2. Edwin Knoppert
    Replies:
    0
    Views:
    386
    Edwin Knoppert
    Dec 29, 2005
  3. nooobody

    bean reflection oddity

    nooobody, Feb 20, 2005, in forum: Java
    Replies:
    4
    Views:
    644
    nooobody
    Feb 20, 2005
  4. Remon van Vliet

    Oddity in ByteBuffer code?

    Remon van Vliet, May 19, 2005, in forum: Java
    Replies:
    5
    Views:
    452
    Chris Uppal
    May 20, 2005
  5. hiwa

    XMLEncoder oddity

    hiwa, Oct 7, 2005, in forum: Java
    Replies:
    16
    Views:
    10,550
Loading...

Share This Page