Manual Pages for UNIX Darwin command on man HTML::Form
MyWebUniversity

Manual Pages for UNIX Darwin command on man HTML::Form

HTML::Form(3) User Contributed Perl Documentation HTML::Form(3)

NAME

HTML::Form - Class that represents an HTML form element

SYNOPSIS

use HTML::Form;

$form = HTML::Form->parse($html, $baseuri);

$form->value(query => "Perl");

use LWP::UserAgent;

$ua = LWP::UserAgent->new;

$response = $ua->request($form->click);

DESCRIPTION

Objects of the "HTML::Form" class represents a single HTML "
...

" instance. A form consists of a sequence of inputs that usually have names, and which can take on various values. The state of a form can be tweaked and it can then be asked to provide "HTTP::Request" objects that can be passed to the request() method of "LWP::UserAgent". The following methods are available:

@forms = HTML::Form->parse( $response )

@forms = HTML::Form->parse( $htmldocument, $base )

@forms = HTML::Form->parse( $htmldocument, %opt )

The parse() class method will parse an HTML document and build up

"HTML::Form" objects for each
element found. If called in

scalar context only returns the first . Returns an empty list if there are no forms to be found.

The $base is the URI used to retrieve the $htmldocument. It is

needed to resolve relative action URIs. If the document was retrieved with LWP then this this parameter is obtained from the

$response->base() method, as shown by the following example:

my $ua = LWP::UserAgent->new;

my $response = $ua->get("http://www.example.com/form.html");

my @forms = HTML::Form->parse($response->decodedcontent,

$response->base);

The parse() method can parse from an "HTTP::Response" object directly, so the example above can be more conveniently written as:

my $ua = LWP::UserAgent->new;

my $response = $ua->get("http://www.example.com/form.html");

my @forms = HTML::Form->parse($response);

Note that any object that implements a decodedcontent() and base() method with similar behaviour as "HTTP::Response" will do. Finally options might be passed in to control how the parse method behaves. The following options are currently recognized: "base" Another way to provide the base URI. "verbose" Print messages to STDERR about any bad HTML form constructs found.

$method = $form->method

$form->method( $newmethod )

This method is gets/sets the method name used for the "HTTP::Request" generated. It is a string like "GET" or "POST".

$action = $form->action

$form->action( $newaction )

This method gets/sets the URI which we want to apply the request method to.

$enctype = $form->enctype

$form->enctype( $newenctype )

This method gets/sets the encoding type for the form data. It is a

string like "application/x-www-form-urlencoded" or

"multipart/form-data".

$value = $form->attr( $name )

$form->attr( $name, $newvalue )

This method give access to the original HTML attributes of the

tag. The $name should always be passed in lower case.

Example:

@f = HTML::Form->parse( $html, $foo );

@f = grep $->attr("id") eq "foo", @f;

die "No form named 'foo' found" unless @f;

$foo = shift @f;

@inputs = $form->inputs

This method returns the list of inputs in the form. If called in scalar context it returns the number of inputs contained in the

form. See "INPUTS" for what methods are available for the input

objects returned.

$input = $form->findinput( $name )

$input = $form->findinput( $name, $type )

$input = $form->findinput( $name, $type, $index )

This method is used to locate specific inputs within the form. All inputs that match the arguments given are returned. In scalar context only the first is returned, or "undef" if none match.

If $name is specified, then the input must have the indicated name.

If $type is specified, then the input must have the specified type.

The following type names are used: "text", "password", "hidden", "textarea", "file", "image", "submit", "radio", "checkbox" and "option".

The $index is the sequence number of the input matched where 1 is

the first. If combined with $name and/or $type then it select the

nth input with the given name and/or type.

$value = $form->value( $name )

$form->value( $name, $newvalue )

The value() method can be used to get/set the value of some input. If no input has the indicated name, then this method will croak. If multiple inputs have the same name, only the first one will be affected. The call:

$form->value('foo')

is a short-hand for:

$form->findinput('foo')->value;

@names = $form->param

@values = $form->param( $name )

$form->param( $name, $value, ... )

$form->param( $name, \@values )

Alternative interface to examining and setting the values of the form. If called without arguments then it returns the names of all the inputs in the form. The names will not repeat even if multiple inputs have the same name. In scalar context the number of different names is returned. If called with a single argument then it returns the value or values of inputs with the given name. If called in scalar context only the first value is returned. If no input exists with the given name, then "undef" is returned. If called with 2 or more arguments then it will set values of the named inputs. This form will croak if no inputs have the given name or if any of the values provided does not fit. Values can also be provided as a reference to an array. This form will allow unsetting all values with the given name as well. This interface resembles that of the param() function of the CGI module.

$form->tryothers( \&callback )

This method will iterate over all permutations of unvisited enumerated values ( elements in the HTML document. An input object basically represents a name/value pair, so when multiple HTML elements contribute to the same name/value pair in the submitted form they are combined.

The input elements that are mapped one-to-one are "text", "textarea",

"password", "hidden", "file", "image", "submit" and "checkbox". For the "radio" and "option" inputs the story is not as simple: All elements with the same name will contribute to the same input radio object. The number of radio input objects will be the same as the number of distinct names used for the elements. For a element there will be one input object for each contained



Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™