perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sumitro Chowdhury <sumitroc...@yahoo.com>
Subject Re: How to parse after reading POST data in mod_perl 2 ?
Date Mon, 04 Nov 2002 16:28:29 GMT
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" <gozer@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


Mime
View raw message