-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

attached is a patch -p1 for libwww-perl-5.805 adding support for <button
type="submit"/> elements to HTML::Form. This allows me to correctly test
my forms using Test::WWW::Mechanize.

Included are three new tests for the following cases:
* multiple <button type="submit"> in one form
* <button> without type attribute (should default to submit)
* <button type="button"> (should not act as submit button)

Relevant standard:
http://www.w3.org/TR/html401/interact/forms.html#h-17.5

I hope I matched the coding style well enough and it works as good for
others as it does for me. Otherwise please feel free to criticise.

Regards,
Stefan Seifert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFQjSQ1QuEJQQMVrgRAqEMAJ9OPAvSlR21sydfQkoFeD7jaROwfwCeO+2D
POC6SjBtOXZrGhkZteguT1Y=
=uPz5
-----END PGP SIGNATURE-----
diff -Naur libwww-perl-5.805/lib/HTML/Form.pm libwww-perl-5.805-html-form-button/lib/HTML/Form.pm
--- libwww-perl-5.805/lib/HTML/Form.pm	2005-12-07 15:32:27.000000000 +0100
+++ libwww-perl-5.805-html-form-button/lib/HTML/Form.pm	2006-10-27 18:13:01.000000000 +0200
@@ -17,7 +17,7 @@
  hidden   => "TextInput",
  textarea => "TextInput",
 
- button   => "IgnoreInput",
+ button   => "SubmitInput",
  "reset"  => "IgnoreInput",
 
  radio    => "ListInput",
@@ -117,7 +117,7 @@
     my $p = HTML::TokeParser->new(ref($html) ? $html->decoded_content(ref => 1) : \$html);
     eval {
 	# optimization
-	$p->report_tags(qw(form input textarea select optgroup option keygen label));
+	$p->report_tags(qw(form input textarea select optgroup option keygen label button));
     };
 
     my $base_uri = delete $opt{base};
@@ -183,6 +183,10 @@
 		    my $type = delete $attr->{type} || "text";
 		    $f->push_input($type, $attr);
 		}
+		elsif ($tag eq "button") {
+		    my $type = delete $attr->{type} || "submit";
+		    $f->push_input($type, $attr) if $type eq "submit";
+		}
 		elsif ($tag eq "textarea") {
 		    $attr->{textarea_value} = $attr->{value}
 		        if exists $attr->{value};
diff -Naur libwww-perl-5.805/t/html/form.t libwww-perl-5.805-html-form-button/t/html/form.t
--- libwww-perl-5.805/t/html/form.t	2005-12-07 15:28:58.000000000 +0100
+++ libwww-perl-5.805-html-form-button/t/html/form.t	2006-10-27 18:12:50.000000000 +0200
@@ -3,7 +3,7 @@
 use strict;
 use Test qw(plan ok);
 
-plan tests => 122;
+plan tests => 125;
 
 use HTML::Form;
 
@@ -503,3 +503,38 @@
 ok(join(":", $f->find_input("r2")->value_names), "two");
 ok(join(":", $f->find_input("r3")->value_names), "nested");
 ok(join(":", $f->find_input("r4")->value_names), "before and after");
+
+# test handling of the button element
+$f = HTML::Form->parse(<<'EOT', 'http://localhost/');
+<form action="">
+  <button type="submit" name="delete" value="1">Delete</button>
+  <button type="submit" name="save" value="1">Save</button>
+</form>
+EOT
+
+ok($f->click('save')->as_string, <<'EOT');
+GET http://localhost/?save=1
+
+EOT
+
+$f = HTML::Form->parse(<<'EOT', 'http://localhost/');
+<form action="">
+  <button name="save" value="1">Save</button>
+</form>
+EOT
+
+ok($f->click->as_string, <<'EOT');
+GET http://localhost/?save=1
+
+EOT
+
+$f = HTML::Form->parse(<<'EOT', 'http://localhost/');
+<form action="">
+  <button type="button" name="save" value="1">Save</button>
+</form>
+EOT
+
+ok($f->click->as_string, <<'EOT');
+GET http://localhost/
+
+EOT

Attachment: html-form-button.diff.sig
Description: PGP signature

Reply via email to