The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::DOM::Element::Form - A Perl class for representing 'form' elements in an HTML DOM tree

SYNOPSIS

  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

DESCRIPTION

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.

This class also inherits from HTML::Form, but is not entirely compatible with its interface. See "HTML::Form COMPATIBILITY", below.

DOM METHODS

In addition to those inherited from HTML::DOM::Element and HTML::DOM::Node, this class implements the following DOM methods:

elements

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).

length

Same as $form->elements->length.

name
acceptCharset
action
enctype
method
target

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.

submit

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 (inherited from HTML::Form) may come in handy.

This method is actually just short for $form->trigger_event('submit'). (See "Other Methods" in HTML::DOM::Node.)

reset

(Not yet implemented)

WWW::Mechanize COMPATIBILITY

In order to work with WWW::Mechanize, this module inherits from, and is partly compatible with the interface of, HTML::Form.

HTML::Form's class methods do not work with this module. If you call HTML::DOM::Element::Form->parse, for instance, you will wreak havoc.

The dump and try_others methods do not currently work.

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.

The method, action, enctype, attr, inputs, find_input, value, param, make_request and form methods should work as expected.

SEE ALSO

HTML::DOM

HTML::DOM::Element

HTML::DOM::Collection::Elements

HTML::Form