Subject: | Problem with HTML::DOM::Element::Form->inputs |
Hi,
I have found a problem that affects reading the inputs that are in a
form. This problem only occurs when a HTML page has multiple forms.
Basically it seems like what ever works out what inputs are in which
form (I could not find it in the code), is not detecting the </form>, so
the first form contains all inputs on the page. Then the second form
contains all the inputs not in the first form. Also it is assigning the
parent form of the input object to always be form1, instead of the form
that it is actually in.
Below is an example of this problem:
Form | Form | input | input
Number | Name | type | value
-----------------------------------------------------------------------
Correct Form1 inputs
-----------------------------------------------------------------------
Form 1 => form_login_compact => hidden => source
Form 1 => form_login_compact => hidden => token
Form 1 => form_login_compact => hidden => id
Form 1 => form_login_compact => hidden => redirect_to
Form 1 => form_login_compact => hidden => qty
Form 1 => form_login_compact => hidden => syndicate_purchase_unique_id
Form 1 => form_login_compact => hidden => referring_url
Form 1 => form_login_compact => hidden => game_offer_id
Form 1 => form_login_compact => text => email
Form 1 => form_login_compact => password => password
Form 1 => form_login_compact => submit => submit
Form 1 => form_login_compact => hidden => md5
------------------------------------------------------------------------
Form2 inputs appearing in Form1
------------------------------------------------------------------------
Form 1 => form_login_compact => option => lottery_id
Form 1 => form_login_compact => text => from_date
Form 1 => form_login_compact => text => from_draw
Form 1 => form_login_compact => submit => Display
------------------------------------------------------------------------
Form2 inputs, they have Form1 as a parent
------------------------------------------------------------------------
Form 2 => form_login_compact => option => lottery_id
Form 2 => form_login_compact => text => from_date
Form 2 => form_login_compact => text => from_draw
Form 2 => form_login_compact => submit => Display
------------------------------------------------------------------------
The above was generated with the following code
------------------------------------------------------------------------
foreach my $form_number (1..2) {
my $form = $mech->form_number($form_number);
my $submit_link = URI->new($form->action)->path;
foreach my $input ($form->inputs) {
my $input_form;
DEBUG($input->{_HTML_DOM_f} . ' ' . $input->{_parent});
if (defined($input->{_HTML_DOM_f}) && $input-
Show quoted text
>{_HTML_DOM_f} =~ m/^HTML::DOM::Element::Form/) {
$input_form = $input->{_HTML_DOM_f}->name;
}
elsif (defined($input->{_parent}) && $input->{_parent}
=~ m/^HTML::DOM::Element::Form/) {
$input_form = $input->{_parent}->name;
}
elsif ($input =~ m/^HTML::DOM::Collection::Options/) {
my $select = $input->[0]->{_parent};
if (defined($select->{_HTML_DOM_f}) && $select-
Show quoted text>{_HTML_DOM_f} =~ m/^HTML::DOM::Element::Form/) {
$input_form = $select->{_HTML_DOM_f}-
Show quoted text>name;
}
elsif (defined($select->{_parent}) && $select-
Show quoted text>{_parent} =~ m/^HTML::DOM::Element::Form/) {
$input_form = $select->{_parent}->name;
}
}
print("Form $form_number => " . $input_form . " => " .
$input->type . " => " . ($input->name || $input->value) . "\n");
}
}