You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Sumitro Chowdhury <su...@yahoo.com> on 2002/10/31 20:41:12 UTC

How to parse after reading POST data in mod_perl 2 ?

Hi all,
Please help ...

Using  Apache/2.0.43 (Unix) mod_perl/1.99_07-dev
Perl/v5.8.0 .

I read in POST data from Form using
$r->read($buff,$r->headers_in->{'Content-length'})

Since I donot use Apache::compat, what API methods are
available to parse this string data ? ( possibly
convert it to a hash )

Cannot use params() from Apache::Request since I have
not installed mod_perl 1.

Thanks,
Sumitro Chowdhury

__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

Re: How to parse after reading POST data in mod_perl 2 ?

Posted by Sumitro Chowdhury <su...@yahoo.com>.
Thanks Philippe for the tip.
After looking at Apache2::Apache::compat and some
input from Randy Kobes, I came up with the following
package called getform.pm which gets the form data
into a hash without using Apache::compat.

(Hope it will help some newbie !!):

package ModPerl::getform;

use strict;
use Apache::Reload;

sub handler {
        my $r = shift;

        $r->content_type('text/html');

        my $form_input;

        # Read in the form - data ....
        #                                             
           
$r->read($form_input,$r->headers_in->{'Content-length'});
        $r->setup_client_block;
        print "Error" unless $r->should_client_block;
       
$r->get_client_block($form_input,$r->headers_in->{'Content-length'});

        my @args = map {
                       
s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
                        s/\+/ /g;
                        $_;
                   } split /[=&;]/, $form_input, -1;

        my %input;
        while (my ($name,$value) = splice @args,0,2) {
                push @{$input{$name}}, $value;
        }

        $r->send_http_header;
        print "<BR>I got the following info:<BR><BR>";

        foreach (keys %input) {
                print "$_ => @{$input{$_}}<BR>";
        }


        return Apache::OK;
}
1;

Thanks guys,
This is a great list.

Sumitro Chowdhury.

--- "Philippe M. Chiasson" <go...@cpan.org> wrote:
> On Fri, 2002-11-01 at 03:41, Sumitro Chowdhury
> wrote:
> > Hi all,
> > Please help ...
> > 
> > Using  Apache/2.0.43 (Unix) mod_perl/1.99_07-dev
> > Perl/v5.8.0 .
> > 
> > I read in POST data from Form using
> > $r->read($buff,$r->headers_in->{'Content-length'})
> > 
> > Since I donot use Apache::compat, what API methods
> are
> > available to parse this string data ? ( possibly
> > convert it to a hash )
> 
> There isn't anything readily avaliabe for the
> moment, but take a look
> at parse_args() in Apache::compat for a good working
> example.
> 
> 
> 
>
--------------------------------------------------------------------------------
> Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: How to parse after reading POST data in mod_perl 2 ?

Posted by Sumitro Chowdhury <su...@yahoo.com>.
Thanks Philippe for the tip.
After looking at Apache2::Apache::compat and some
input from Randy Kobes, I came up with the following
package called getform.pm which gets the form data
into a hash without using Apache::compat.

(Hope it will help some newbie !!):

package ModPerl::getform;

use strict;
use Apache::Reload;

sub handler {
        my $r = shift;

        $r->content_type('text/html');

        my $form_input;

        # Read in the form - data ....
        #                                             
           
$r->read($form_input,$r->headers_in->{'Content-length'});
        $r->setup_client_block;
        print "Error" unless $r->should_client_block;
       
$r->get_client_block($form_input,$r->headers_in->{'Content-length'});

        my @args = map {
                       
s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
                        s/\+/ /g;
                        $_;
                   } split /[=&;]/, $form_input, -1;

        my %input;
        while (my ($name,$value) = splice @args,0,2) {
                push @{$input{$name}}, $value;
        }

        $r->send_http_header;
        print "<BR>I got the following info:<BR><BR>";

        foreach (keys %input) {
                print "$_ => @{$input{$_}}<BR>";
        }


        return Apache::OK;
}
1;

Thanks guys,
This is a great list.

Sumitro Chowdhury.

--- "Philippe M. Chiasson" <go...@cpan.org> wrote:
> On Fri, 2002-11-01 at 03:41, Sumitro Chowdhury
> wrote:
> > Hi all,
> > Please help ...
> > 
> > Using  Apache/2.0.43 (Unix) mod_perl/1.99_07-dev
> > Perl/v5.8.0 .
> > 
> > I read in POST data from Form using
> > $r->read($buff,$r->headers_in->{'Content-length'})
> > 
> > Since I donot use Apache::compat, what API methods
> are
> > available to parse this string data ? ( possibly
> > convert it to a hash )
> 
> There isn't anything readily avaliabe for the
> moment, but take a look
> at parse_args() in Apache::compat for a good working
> example.
> 
> 
> 
>
--------------------------------------------------------------------------------
> Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/

Re: How to parse after reading POST data in mod_perl 2 ?

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Fri, 2002-11-01 at 03:41, Sumitro Chowdhury wrote:
> Hi all,
> Please help ...
> 
> Using  Apache/2.0.43 (Unix) mod_perl/1.99_07-dev
> Perl/v5.8.0 .
> 
> I read in POST data from Form using
> $r->read($buff,$r->headers_in->{'Content-length'})
> 
> Since I donot use Apache::compat, what API methods are
> available to parse this string data ? ( possibly
> convert it to a hash )

There isn't anything readily avaliabe for the moment, but take a look
at parse_args() in Apache::compat for a good working example.

> Cannot use params() from Apache::Request since I have
> not installed mod_perl 1.
> 
> Thanks,
> Sumitro Chowdhury
> 
> __________________________________________________
> Do you Yahoo!?
> HotJobs - Search new jobs daily now
> http://hotjobs.yahoo.com/
> 
-- 


--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5
(122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so
ingenious.
perl
-e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org