You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by David Hofmann <mo...@hotmail.com> on 2004/08/19 16:16:56 UTC

Apache::Request multivalued parameters

I have a form where several of the in hidden fields are named the same thing 
with diffrent values.

With CGI.pm the I can use %in = $readquery->Vars; to put everything in a 
hash. Then I break the values base on \0.

What the best way to do this with Apache::Request, and how does it handle 
multivalued parameters ?

David

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request multivalued parameters

Posted by Tom Schindl <to...@gmx.at>.
Hi,

I've never used $query->Vars but as far as I know Apache::Request does 
not provide a method like this. If the rest of your app depends on this 
behaviour you'll have to construct it your own like this:

------------------8<------------------
my %params = ();

while( $apr->param ) {
    $params{$_} = (join chr(0), $apr->param($_));
}
------------------8<------------------


if your app does not depend on such a hash I'd do the following:

------------------8<------------------
my %params = ();

while( $apr->param ) {
    $params{$_} = [ $apr->param($_) ];
}
------------------8<------------------

Still the best way is to pass around the Apache::Request object or at 
least the Request-object you received because you can always use 
Apache::Request->instance($r) to get the same Apache::Request-object 
back in any function/method you're calling.

Tom

David Hofmann wrote:
> I have a form where several of the in hidden fields are named the same 
> thing with diffrent values.
> 
> With CGI.pm the I can use %in = $readquery->Vars; to put everything in a 
> hash. Then I break the values base on \0.
> 
> What the best way to do this with Apache::Request, and how does it 
> handle multivalued parameters ?
> 
> David
> 
> _________________________________________________________________
> Don’t just search. Find. Check out the new MSN Search! 
> http://search.msn.click-url.com/go/onm00200636ave/direct/01/
> 
> 


Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache::Request multivalued parameters

Posted by Joe Schaefer <jo...@sunstarsys.com>.
"David Hofmann" <mo...@hotmail.com> writes:

> I have a form where several of the in hidden fields are named the same thing
> with diffrent values.
> 
> With CGI.pm the I can use %in = $readquery->Vars; to put everything in a
> hash. Then I break the values base on \0.
> 
> What the best way to do this with Apache::Request, and how does it handle
> multivalued parameters ?

You have quite a few options here:

  1) Work with the Apache::Request::Table

        $t = $req->param;

     and use each(%$t), keys(%$t) and values(%$t) to iterate over the params
     in document order (query_string args come first, then the POST
     data in the order it was received).  To get all entries for a 
     given parameter, you can use 
  
        @foo_vals = $t->get("foo");

     You can also use $t->do(...) to iterate over the table entries with
     a callback sub.

  2) Think of the $req->param method as a "smart-hash", and use it in
     the same way you'd use CGI::param (since that's the method 
     it is patterened after).

  3) Try to stop using the $readquery->Vars API, since $req->param is 
     able to decode binary data with embedded '\0' values in them.
     If you can't bring yourself to that, just write your own converter:

    sub Vars {
        my $req = shift;
        map { $_ => join "\0", $req->param($_) } $req->param;
    }


I hope this helps.

-- 
Joe Schaefer


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html