Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

parse multipart/form-data into a hash structure

by pg (Canon)
on Oct 04, 2005 at 22:53 UTC ( #497428=snippet: print w/ replies, xml ) Need Help??

Description:

This sub takes a HTTP::Request, and returns a hash data structure that contains all form fields. If you have a form field named "blah", and the returned hash is stored in $form_data, then you can get the value for blah through $form_data->{"blah"}.

The asumption is that the form use multipart/form-data encoding. The code is something I use, and not heavily tested with differnt situations.

sub analyze_request {
    my $req = shift;
    my $form_data;
    for my $part ($req->parts()) {
        if (my $content_disposition = $part->headers->header("Content-
+Disposition")) {
            if ($content_disposition =~ /^form-data; name=\"(.*?)\"/) 
+{
                $form_data->{$1} = $part->content();
            }
        }
    }
    return $form_data;
}
Comment on parse multipart/form-data into a hash structure
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://497428]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-04-23 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls