Father Chrysostomos > HTML-DOM-0.053 > HTML::DOM::Element::Form

Download:
HTML-DOM-0.053.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Stalled  1
View/Report Bugs
Module Version: 0.053   Source  

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 tries to mimic HTML::Form, but is not entirely compatible with its interface. See "WWW::Mechanize 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 may come in handy.

This method is actually just short for $form->trigger_event('submit'). (See HTML::DOM::EventTarget.)

reset

This triggers the form's 'reset' event.

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

WWW::Mechanize COMPATIBILITY ^

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.

The dump and try_others methods do not exist either.

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

syntax highlighting: