[html-formfu] submitting forms via an image input

Carl Franks fireartist at gmail.com
Wed Sep 2 16:51:29 GMT 2009


Hi,

Thanks for the patch.
I'm going to have to think of a way to make it more robust, though.
Because nested_name() builds field names of the form "foo.bar", this
could lead to clashes.

If submitted() initially fails, it could maybe search the form for an
Image element, and then check against its name. - It would need to
handle both indicator() being explicitly set, and not being set.

Carl


2009/9/2 Kahlil Hodgson <kahlil.hodgson at dealmax.com.au>:
> 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
>
>
> Index: t/form/submited_via_image.t
> ===================================================================
> --- 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 => 1;
> +
> +use HTML::FormFu;
> +
> +my $form = HTML::FormFu->new;
> +
> +$form->populate(
> +    {
> +        indicator => 'submit',
> +        elements => [
> +            {
> +                type => 'Image',
> +                name => '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' => '1'});
> +
> +ok($form->submitted, 'submit image is an indicator');
> +
> Index: lib/HTML/FormFu.pm
> ===================================================================
> --- 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 => $indicator );
>
> -        $code = 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 coords.
> +        # If this kind of field is being used as an indicator, we check for an
> +        # x coordinate just in case.
> +        $code = sub {
> +            return defined $query->param($indicator) ||
> +                   defined $query->param("$indicator.x")
> +        };
>     }
>     elsif ( !defined $indicator ) {
>         my @names = uniq
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>



More information about the HTML-FormFu mailing list