Subject: | Disabled, checked radiobutton being submitted [patch] |
When I have a disabled, checked radiobutton and a hidden field, both
with the same name, the disabled radiobutton "succeeds" and it's value
is submitted by HTML::Form.
If I understand section 17.12.1 "Disabled controls"¹ in the HTML 4.01
standard correctly, the radiobutton should not succeed when disabled,
and this following test should be valid (patch against
libwww-perl-5.808, Debian testing):
--- t/html/form.t.orig 2008-02-12 10:33:18.000000000 +0100
+++ t/html/form.t 2008-02-12 10:34:20.000000000 +0100
@@ -3,7 +3,7 @@
use strict;
use Test qw(plan ok);
-plan tests => 122;
+plan tests => 123;
use HTML::Form;
@@ -417,6 +417,20 @@
ok(eval{$f->find_input("m3", undef, 2)->value(undef)}, undef);
ok($@ && $@ =~ /^The 'm3' field can't be unchecked/);
+# Try a disabled radiobutton:
+$f = HTML::Form->parse(<<EOT, "http://localhost/");
+<form>
+ <input disabled checked type=radio name=f value=a>
+ <input type=hidden name=f value=b>
+</form>
+
+EOT
+
+ok($f->click->as_string, <<'EOT');
+GET http://localhost/?f=b
+
+EOT
+
$f = HTML::Form->parse(<<EOT, "http://www.example.com");
<!-- from http://www.blooberry.com/indexdot/html/tagpages/k/keygen.htm -->
<form METHOD="post" ACTION="http://example.com/secure/keygen/test.cgi"
ENCTYPE="application/x-www-form-urlencoded">
(Neither Mozilla nor Microsoft Internet Explorer submits the radiobutton
value, not that that proves anything...)
Here is a patch that fixes the problem for me:
--- lib/HTML/Form.pm.orig 2008-02-12 11:27:05.000000000 +0100
+++ lib/HTML/Form.pm 2008-02-12 11:22:57.000000000 +0100
@@ -903,7 +903,7 @@
my $self = shift;
my $name = $self->{'name'};
return unless defined $name;
- return if $self->{disabled};
+ return if $self->disabled;
my $value = $self->value;
return unless defined $value;
return ($name => $value);
P.S. I wasn't sure if writing this on the mailinglist was sufficient, so
I have created this bug-report as well.
¹ <http://www.w3.org/TR/html4/interact/forms.html#adef-disabled>