"Darrell Gammill" <[EMAIL PROTECTED]> writes:

> The 'Anthropology' option is being interpreted as its own separate input
> rather then part of the 'u_input' input.  To test this, I used the
> section of code below with the results right after it.

Thanks for the test case.  This is a bug in HTML::Form.  The 'name'
from the option tag overrides the 'name' from the select tag when it
should not.  We also get in trouble with (illegal) option attributes
like 'disabled', 'multiple', 'type' etc.

The following patch fixes these problems.  It will be in the next
libwww-perl.

Regards,
Gisle

Index: Form.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/HTML/Form.pm,v
retrieving revision 1.39
diff -u -p -r1.39 Form.pm
--- Form.pm     9 Apr 2004 14:17:32 -0000       1.39
+++ Form.pm     3 Jun 2004 09:13:44 -0000
@@ -136,15 +136,26 @@ sub parse
                    $f->push_input("textarea", $attr);
                }
                elsif ($tag eq "select") {
-                   $attr->{select_value} = $attr->{value}
-                       if exists $attr->{value};
+                   # rename attributes reserved to come for the option tag
+                   for ("value", "value_name") {
+                       $attr->{"select_$_"} = delete $attr->{$_}
+                           if exists $attr->{$_};
+                   }
                    while ($t = $p->get_tag) {
                        my $tag = shift @$t;
                        last if $tag eq "/select";
                        next if $tag =~ m,/?optgroup,;
                        next if $tag eq "/option";
                        if ($tag eq "option") {
-                           my %a = (%$attr, %{$t->[0]});
+                           my %a = %{$t->[0]};
+                           # rename keys so they don't clash with %attr
+                           for (keys %a) {
+                               next if $_ eq "value";
+                               $a{"option_$_"} = delete $a{$_};
+                           }
+                           while (my($k,$v) = each %$attr) {
+                               $a{$k} = $v;
+                           }
                            $a{value_name} = $p->get_trimmed_text;
                            $a{value} = delete $a{value_name}
                                unless defined $a{value};
@@ -192,6 +203,7 @@ sub push_input
     my @extra;
     push(@extra, readonly => 1) if $type eq "hidden";
 
+    delete $attr->{type}; # don't confuse the type argument
     my $input = $class->new(type => $type, %$attr, @extra);
     $input->add_to_form($self);
 }
@@ -913,9 +925,9 @@ sub new
     }
     else {
        $self->{menu} = [$value];
-       my $checked = exists $self->{checked} || exists $self->{selected};
+       my $checked = exists $self->{checked} || exists $self->{option_selected};
        delete $self->{checked};
-       delete $self->{selected};
+       delete $self->{option_selected};
        if (exists $self->{multiple}) {
            unshift(@{$self->{menu}}, undef);
            $self->{value_names} = ["off", $value_name];

Reply via email to