HTML::DOM::Element::Form - A Perl class for representing 'form' elements in an HTML DOM tree
use HTML::DOM; $doc = HTML::DOM->new; $elem = $doc->createElement('form'); $elem->method('GET') # set attribute $elem->method; # get attribute $elem->enctype; $elem->tagName; # etc
This class implements 'form' elements in an HTML::DOM tree. It implements the HTMLFormElement DOM interface and inherits from HTML::DOM::Element (q.v.).
A form object can be used as a hash or an array, to access its input fields, so $form->[0] and $form->{name} are shorthand for $form->elements->[0] and $form->elements->{name}, respectively.
$form->[0]
$form->{name}
$form->elements->[0]
$form->elements->{name}
This class also tries to mimic HTML::Form, but is not entirely compatible with its interface. See "WWW::Mechanize COMPATIBILITY", below.
In addition to those inherited from HTML::DOM::Element and HTML::DOM::Node, this class implements the following DOM methods:
Returns a collection (HTML::DOM::Collection::Elements object) in scalar context, or a list in list context, of all the input fields this form contains. This differs slightly from the inputs method (part of the HTML::Form interface) in that it includes 'button' elements, whereas inputs does not (though it does include 'input' elements with 'button' for the type).
inputs
Same as $form->elements->length.
$form->elements->length
Each of these returns the corresponding HTML attribute (acceptCharset corresponds to the 'accept-charset' attribute). If you pass an argument, it will become the new value of the attribute, and the old value will be returned.
acceptCharset
This triggers the form's 'submit' event, calling the default event handler (see "EVENT HANDLING" in HTML::DOM). It is up to the default event handler to take any further action. The form's make_request method may come in handy.
make_request
This method is actually just short for $form->trigger_event('submit'). (See HTML::DOM::EventTarget.)
This triggers the form's 'reset' event.
This class overrides the superclasses' method to trigger the default event handler for form submissions, when the submit event occurs, and reset the form when a reset event occurs.
In order to work with WWW::Mechanize, this module mimics, and is partly compatible with the interface of, HTML::Form.
HTML::Form's class methods do not apply. If you call HTML::DOM::Element::Form->parse, for instance, you'll just get an error, because it doesn't exist.
HTML::DOM::Element::Form->parse
The dump and try_others methods do not exist either.
dump
try_others
The click method behaves differently from HTML::Form's, in that it does not call make_request, but triggers a 'click' event if there is a button to click, or a 'submit' event otherwise.
click
The method, action, enctype, attr, inputs, find_input, value, param, make_request and form methods should work as expected.
method
action
enctype
attr
find_input
value
param
form
HTML::DOM
HTML::DOM::Element
HTML::DOM::Collection::Elements
HTML::Form
To install HTML::DOM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::DOM
CPAN shell
perl -MCPAN -e shell install HTML::DOM
For more information on module installation, please visit the detailed CPAN module installation guide.