[html-formfu] submitting forms via an image input

Kahlil Hodgson kahlil.hodgson at dealmax.com.au
Wed Sep 2 00:25:18 GMT 2009


Hi,

Some user agents (e.g. LWP and IE6) do not set the value of an input
field of type 'image', they just set the x and y coords.  This can be a
problem if you use an image field as an indicator: your test suite fails
but everything works fine in Firefox.  You can get around this by
setting your indicator to an appropriate CODE ref, but since it took a
fair amount of head scratching for me to figure this one out, I thought
we could just tweak the code a little to avoid the problem in general.
I've attached a simple patch against SVN that fixes the issue.

Cheers!

Kal


-- =

Kahlil (Kal) Hodgson                       GPG: C37B01F4
Head of Technology                         (m) +61 (0) 4 2573 0382
DealMax Pty Ltd                            (w) +61 (0) 3 9008 5281

Suite 1005
401 Docklands Drive
Docklands VIC 3008 Australia

"All parts should go together without forcing.  You must remember that
the parts you are reassembling were disassembled by you.  Therefore,
if you can't get them together again, there must be a reason.  By all
means, do not use a hammer."  -- IBM maintenance manual, 1925

-------------- next part --------------
Index: t/form/submited_via_image.t
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- t/form/submited_via_image.t	(revision 0)
+++ t/form/submited_via_image.t	(revision 0)
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+use Test::More tests =3D> 1;
+
+use HTML::FormFu;
+
+my $form =3D HTML::FormFu->new;
+
+$form->populate(
+    {
+        indicator =3D> 'submit',
+        elements =3D> [
+            {
+                type =3D> 'Image',
+                name =3D> 'submit',
+            }
+        ],
+    }
+);
+
+# simulate a click on the image -- some UAs (LWP and IE6) set the x and y =

+# co-ords but not the value
+$form->process({'submit.x' =3D> '1'});
+
+ok($form->submitted, 'submit image is an indicator');
+
Index: lib/HTML/FormFu.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/HTML/FormFu.pm	(revision 1590)
+++ lib/HTML/FormFu.pm	(working copy)
@@ -369,7 +369,14 @@
     if ( defined($indicator) && ref $indicator ne 'CODE' ) {
         DEBUG_PROCESS && debug( INDICATOR =3D> $indicator );
 =

-        $code =3D sub { return defined $query->param($indicator) };
+        # Some user agents (e.g. LWP and IE6) do not set the value of
+        # an input field of type 'image' -- they just set the x and y coor=
ds.  =

+        # If this kind of field is being used as an indicator, we check fo=
r an =

+        # x coordinate just in case.
+        $code =3D sub { =

+            return defined $query->param($indicator) ||
+                   defined $query->param("$indicator.x") =

+        };
     }
     elsif ( !defined $indicator ) {
         my @names =3D uniq


More information about the HTML-FormFu mailing list