Subject: | no support for multiple CGI values |
Apache::MVC clobbers multiple values for a CGI parameter.
E.g.:
<option name="foo" multiple="1">
<select>abc</select>
<select>def</select>
<select>ghi</select>
</option>
Only one value will be in $r->{params}{foo} even if multiple values are selected.
In addition, $r->{params} is populated by calling Apache->content(), after which the request body is no longer available. So it's not possible to call Apache::Request->param() or CGI->param(), etc.
You can workaround it by defining parse_location() in your driver class, but that doesn't feel like the right thing to do.
Attached is a patch to Apache::MVC that populates $r->{params} with Apache::Request->param(). It preserves multiple values and still allows further manipulation of the parameters.
This solution isn't problem-free. When you access the parameters in your model class you need to check whether you have one value or a list of values. A more robust solution might be to dispatch $r->param() to $r->{ar}->param() so it returns a single value or a list depending on context. I could do that in my driver class if it hadn't already called Apache->content().
Index: lib/Apache/MVC.pm
===================================================================
RCS file: /var/cvs/modules/Apache-MVC/lib/Apache/MVC.pm,v
retrieving revision 1.22
diff -U2 -r1.22 MVC.pm
--- lib/Apache/MVC.pm 21 Jun 2004 13:29:11 -0000 1.22
+++ lib/Apache/MVC.pm 9 Aug 2004 19:58:35 -0000
@@ -18,8 +18,10 @@
$self->{path} =~ s/^($loc)?\///;
$self->parse_path;
-
- $self->{params} = { $self->{ar}->content };
- while (my ($key, $value) = each %{$self->{params}}) {
- $self->{params}{$key} = '' unless defined $value;
+ for ($self->{ar}->param()) {
+ my @values = $self->{ar}->param($_);
+ @values = map {defined() ? $_ : ''} @values;
+ $self->{params}{$_} = @values > 1 ? \@values
+ : @values ? $values[0]
+ : '';
}
$self->{query} = { $self->{ar}->args };