From: James Taylor <[EMAIL PROTECTED]> > Chris Devers wrote: > > On Fri, 10 Dec 2004, James Taylor wrote: > > > > > >>Hi everyone, wondering if anyone knew how to pass an associative > >>array via POST to mod_perl. Something like: > > > > > > HTML forms don't really provide for complex data structures, so any > > solution is going to have to be cobbled together. > > > > I think your best bet is to just have form elements with names like > > 'searchname', 'searchemail', etc, and just have code on the server > > to organize it into a hash: > > > > $search{name} = $req->param('searchname'); > > $search{email} = $req->param('searchemail'); > > > > etc. > > Eh, score 1 for PHP then. The reason I can't specifically do what > you're mentioning is that the field names being passed could be > ANYTHING, as the code is for a module I'm writing. Anyway, I went > ahead and just made it cheesy, instead of doing field[something], i > made all of the input names "field=something", send the hash through a > foreach loop - if the name of the field =~ /field/, i split on the = > and ditch the first variable. Feh
Specialized tools often give you shortcuts for their special stuff (and fail badly as soon as you try to do something too general). %params = $req->Vars; foreach my $key (keys %params) { next unless $key =~ /^([^\[]+)\[([^\]]+)\]$/; $params->{$1}->{$2} = $params->{$key}; delete $params->{$key}; } doesn't look to complex to me and you end up with ?search[name]=Jenda&[EMAIL PROTECTED]&page=1 being converted to %params = ( search => { name => 'Jenda', 'email' => '[EMAIL PROTECTED]'}, page => 1 ) Is that what you wanted? Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>