Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

is a WWW::Mechanize bug or my ignorance?

by way (Sexton)
on Mar 19, 2009 at 21:31 UTC ( #751884=perlquestion: print w/replies, xml ) Need Help??
way has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I'm playing with WWW::Mechanize and when I send a form "clicking" an image button, mechanize don't send the value of it. Let me explain with an example:

if I have this index1.html page:

<form action="http://localhost/"> <input type=image src=send.gif name=some value=thisvalue> </form>
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get('http://localhost/index1.html'); $mech->click_button(name => 'some'); # it not send the value -> "thisv +alue"!

In fact the error is on HTML::Form so, if it's an error where i reporte that, on WWW::Mechanize or on HTML::Form?

Replies are listed 'Best First'.
Re: is a WWW::Mechanize bug or my ignorance?
by ikegami (Pope) on Mar 19, 2009 at 21:51 UTC

    Going by the spec, it's not a bug. I had to fix the missing quote in your HTML and the incorrect argument to click_button in your code to test it ( since fixed in the OP ), but mech does perform the prescribed action:

    When a pointing device is used to click on the image, the form is submitted and the click coordinates passed to the server. The x value is measured in pixels from the left of the image, and the y value in pixels from the top of the image. The submitted data includes name.x=x-value and name.y=y-value where "name" is the value of the name attribute, and x-value and y-value are the x and y coordinate values, respectively.

    Specifically, it sends some.x=1 and some.y=1 as it should. Sending some=thisvalue would be wrong.

    The HTML5 spec clarifies many ambiguities in HTML4. It says the following the values of image buttons must be:

    A coordinate, relative to a particular image's size, with the extra semantic that it must be the last value selected and initiates form submission

    The table is very specific and comprehensive. Not only shouldn't "thisvalue" be sent, it isn't even a valid value for a <input type="image">.

    Update: Added HTML5's view.

    Update: Interestingly, IE is actually following the spec, and FF isn't.

      Not wrong, but optional.
        "Not conforming to the spec", if you prefer.
Re: is a WWW::Mechanize bug or my ignorance?
by Anonymous Monk on Mar 19, 2009 at 21:59 UTC
    It is HTML::Form bug, report it here. Here's a workaround :)
    sub HTML::Form::ImageInput::form_name_value { my $self = shift; my $clicked = $self->{clicked}; return unless $clicked; return if $self->{disabled}; my $name = $self->{name}; $name = (defined($name) && length($name)) ? "$name." : ""; return ("${name}x" => $clicked->[0], "${name}y" => $clicked->[1], "$$self{name}" => $self->value, ); }

      Thank you by the workaround i report it now, Cheers!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://751884]
Approved by ikegami
[marto]: nice
[choroba]: New blogpost after a long pause!
marto needs to think of a joke where the punchline is "why the long paws?"

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-03-20 16:24 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (254 votes). Check out past polls.