.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "HTML::Form 3" .TH HTML::Form 3 "2004-04-06" "perl v5.8.4" "User Contributed Perl Documentation" .SH "NAME" HTML::Form \- Class that represents an HTML form element .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use HTML::Form; \& $form = HTML::Form->parse($html, $base_uri); \& $form->value(query => "Perl"); .Ve .PP .Vb 3 \& use LWP::UserAgent; \& $ua = LWP::UserAgent->new; \& $response = $ua->request($form->click); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Objects of the \f(CW\*(C`HTML::Form\*(C'\fR class represents a single \s-1HTML\s0 \&\f(CW\*(C`
...
\*(C'\fR 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 \f(CW\*(C`HTTP::Request\*(C'\fR objects that can be passed to the \&\fIrequest()\fR method of \f(CW\*(C`LWP::UserAgent\*(C'\fR. .PP The following methods are available: .ie n .IP "@forms = HTML::Form\->parse( $response )" 4 .el .IP "@forms = HTML::Form\->parse( \f(CW$response\fR )" 4 .IX Item "@forms = HTML::Form->parse( $response )" .PD 0 .ie n .IP "@forms = HTML::Form\->parse( $html_document\fR, \f(CW$base )" 4 .el .IP "@forms = HTML::Form\->parse( \f(CW$html_document\fR, \f(CW$base\fR )" 4 .IX Item "@forms = HTML::Form->parse( $html_document, $base )" .ie n .IP "@forms = HTML::Form\->parse( $html_document\fR, \f(CW%opt )" 4 .el .IP "@forms = HTML::Form\->parse( \f(CW$html_document\fR, \f(CW%opt\fR )" 4 .IX Item "@forms = HTML::Form->parse( $html_document, %opt )" .PD The \fIparse()\fR class method will parse an \s-1HTML\s0 document and build up \&\f(CW\*(C`HTML::Form\*(C'\fR 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. .Sp The \f(CW$base\fR is the \s-1URI\s0 used to retrieve the \f(CW$html_document\fR. It is needed to resolve relative action URIs. If the document was retrieved with \s-1LWP\s0 then this this parameter is obtained from the \&\f(CW$response\fR\->\fIbase()\fR method, as shown by the following example: .Sp .Vb 4 \& my $ua = LWP::UserAgent->new; \& my $response = $ua->get("http://www.example.com/form.html"); \& my @forms = HTML::Form->parse($response->decoded_content, \& $response->base); .Ve .Sp The \fIparse()\fR method can parse from an \f(CW\*(C`HTTP::Response\*(C'\fR object directly, so the example above can be more conveniently written as: .Sp .Vb 3 \& my $ua = LWP::UserAgent->new; \& my $response = $ua->get("http://www.example.com/form.html"); \& my @forms = HTML::Form->parse($response); .Ve .Sp Note that any object that implements a \fIdecoded_content()\fR and \fIbase()\fR method with similar behaviour as \f(CW\*(C`HTTP::Response\*(C'\fR will do. .Sp Finally options might be passed in to control how the parse method behaves. The following options are currently recognized: .RS 4 .ie n .IP """base""" 4 .el .IP "\f(CWbase\fR" 4 .IX Item "base" Another way to provide the base \s-1URI\s0. .ie n .IP """verbose""" 4 .el .IP "\f(CWverbose\fR" 4 .IX Item "verbose" Print messages to \s-1STDERR\s0 about any bad \s-1HTML\s0 form constructs found. .RE .RS 4 .RE .ie n .IP "$method = $form\->method" 4 .el .IP "$method = \f(CW$form\fR\->method" 4 .IX Item "$method = $form->method" .PD 0 .ie n .IP "$form\->method( $new_method )" 4 .el .IP "$form\->method( \f(CW$new_method\fR )" 4 .IX Item "$form->method( $new_method )" .PD This method is gets/sets the \fImethod\fR name used for the \&\f(CW\*(C`HTTP::Request\*(C'\fR generated. It is a string like \*(L"\s-1GET\s0\*(R" or \*(L"\s-1POST\s0\*(R". .ie n .IP "$action = $form\->action" 4 .el .IP "$action = \f(CW$form\fR\->action" 4 .IX Item "$action = $form->action" .PD 0 .ie n .IP "$form\->action( $new_action )" 4 .el .IP "$form\->action( \f(CW$new_action\fR )" 4 .IX Item "$form->action( $new_action )" .PD This method gets/sets the \s-1URI\s0 which we want to apply the request \&\fImethod\fR to. .ie n .IP "$enctype = $form\->enctype" 4 .el .IP "$enctype = \f(CW$form\fR\->enctype" 4 .IX Item "$enctype = $form->enctype" .PD 0 .ie n .IP "$form\->enctype( $new_enctype )" 4 .el .IP "$form\->enctype( \f(CW$new_enctype\fR )" 4 .IX Item "$form->enctype( $new_enctype )" .PD This method gets/sets the encoding type for the form data. It is a string like \*(L"application/x\-www\-form\-urlencoded\*(R" or \*(L"multipart/form\-data\*(R". .ie n .IP "$value = $form\fR\->attr( \f(CW$name )" 4 .el .IP "$value = \f(CW$form\fR\->attr( \f(CW$name\fR )" 4 .IX Item "$value = $form->attr( $name )" .PD 0 .ie n .IP "$form\->attr( $name\fR, \f(CW$new_value )" 4 .el .IP "$form\->attr( \f(CW$name\fR, \f(CW$new_value\fR )" 4 .IX Item "$form->attr( $name, $new_value )" .PD This method give access to the original \s-1HTML\s0 attributes of the tag. The \f(CW$name\fR should always be passed in lower case. .Sp Example: .Sp .Vb 4 \& @f = HTML::Form->parse( $html, $foo ); \& @f = grep $_->attr("id") eq "foo", @f; \& die "No form named 'foo' found" unless @f; \& $foo = shift @f; .Ve .ie n .IP "@inputs = $form\->inputs" 4 .el .IP "@inputs = \f(CW$form\fR\->inputs" 4 .IX Item "@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 \*(L"\s-1INPUTS\s0\*(R" for what methods are available for the input objects returned. .ie n .IP "$input = $form\fR\->find_input( \f(CW$name )" 4 .el .IP "$input = \f(CW$form\fR\->find_input( \f(CW$name\fR )" 4 .IX Item "$input = $form->find_input( $name )" .PD 0 .ie n .IP "$input = $form\fR\->find_input( \f(CW$name\fR, \f(CW$type )" 4 .el .IP "$input = \f(CW$form\fR\->find_input( \f(CW$name\fR, \f(CW$type\fR )" 4 .IX Item "$input = $form->find_input( $name, $type )" .ie n .IP "$input = $form\fR\->find_input( \f(CW$name\fR, \f(CW$type\fR, \f(CW$index )" 4 .el .IP "$input = \f(CW$form\fR\->find_input( \f(CW$name\fR, \f(CW$type\fR, \f(CW$index\fR )" 4 .IX Item "$input = $form->find_input( $name, $type, $index )" .PD 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 \f(CW\*(C`undef\*(C'\fR if none match. .Sp If \f(CW$name\fR is specified, then the input must have the indicated name. .Sp If \f(CW$type\fR is specified, then the input must have the specified type. The following type names are used: \*(L"text\*(R", \*(L"password\*(R", \*(L"hidden\*(R", \&\*(L"textarea\*(R", \*(L"file\*(R", \*(L"image\*(R", \*(L"submit\*(R", \*(L"radio\*(R", \*(L"checkbox\*(R" and \*(L"option\*(R". .Sp The \f(CW$index\fR is the sequence number of the input matched where 1 is the first. If combined with \f(CW$name\fR and/or \f(CW$type\fR then it select the \fIn\fRth input with the given name and/or type. .ie n .IP "$value = $form\fR\->value( \f(CW$name )" 4 .el .IP "$value = \f(CW$form\fR\->value( \f(CW$name\fR )" 4 .IX Item "$value = $form->value( $name )" .PD 0 .ie n .IP "$form\->value( $name\fR, \f(CW$new_value )" 4 .el .IP "$form\->value( \f(CW$name\fR, \f(CW$new_value\fR )" 4 .IX Item "$form->value( $name, $new_value )" .PD The \fIvalue()\fR method can be used to get/set the value of some input. If no input has the indicated name, then this method will croak. .Sp If multiple inputs have the same name, only the first one will be affected. .Sp The call: .Sp .Vb 1 \& $form->value('foo') .Ve .Sp is a short-hand for: .Sp .Vb 1 \& $form->find_input('foo')->value; .Ve .ie n .IP "@names = $form\->param" 4 .el .IP "@names = \f(CW$form\fR\->param" 4 .IX Item "@names = $form->param" .PD 0 .ie n .IP "@values = $form\fR\->param( \f(CW$name )" 4 .el .IP "@values = \f(CW$form\fR\->param( \f(CW$name\fR )" 4 .IX Item "@values = $form->param( $name )" .ie n .IP "$form\->param( $name\fR, \f(CW$value, ... )" 4 .el .IP "$form\->param( \f(CW$name\fR, \f(CW$value\fR, ... )" 4 .IX Item "$form->param( $name, $value, ... )" .ie n .IP "$form\->param( $name, \e@values )" 4 .el .IP "$form\->param( \f(CW$name\fR, \e@values )" 4 .IX Item "$form->param( $name, @values )" .PD Alternative interface to examining and setting the values of the form. .Sp 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. .Sp 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 \&\f(CW\*(C`undef\*(C'\fR is returned. .Sp 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. .Sp This interface resembles that of the \fIparam()\fR function of the \s-1CGI\s0 module. .IP "$form\->try_others( \e&callback )" 4 .IX Item "$form->try_others( &callback )" This method will iterate over all permutations of unvisited enumerated values ( \fIelements\fR in the \s-1HTML\s0 document. An input object basically represents a name/value pair, so when multiple \&\s-1HTML\s0 elements contribute to the same name/value pair in the submitted form they are combined. .PP The input elements that are mapped one-to-one are \*(L"text\*(R", \*(L"textarea\*(R", \&\*(L"password\*(R", \*(L"hidden\*(R", \*(L"file\*(R", \*(L"image\*(R", \*(L"submit\*(R" and \*(L"checkbox\*(R". For the \*(L"radio\*(R" and \*(L"option\*(R" 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