{
    "content": [
        {
            "type": "text",
            "text": "# HTML::Form (perldoc)\n\n## NAME\n\nHTML::Form - Class that represents an HTML form element\n\n## SYNOPSIS\n\nuse HTML::Form;\n$form = HTML::Form->parse($html, $baseuri);\n$form->value(query => \"Perl\");\nuse LWP::UserAgent;\n$ua = LWP::UserAgent->new;\n$response = $ua->request($form->click);\n\n## DESCRIPTION\n\nObjects of the \"HTML::Form\" class represents a single HTML \"<form> ... </form>\" instance. A form\nconsists of a sequence of inputs that usually have names, and which can take on various values.\nThe state of a form can be tweaked and it can then be asked to provide HTTP::Request objects\nthat can be passed to the request() method of LWP::UserAgent.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **INPUTS**\n- **SEE ALSO**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "HTML::Form",
        "section": "",
        "mode": "perldoc",
        "summary": "HTML::Form - Class that represents an HTML form element",
        "synopsis": "use HTML::Form;\n$form = HTML::Form->parse($html, $baseuri);\n$form->value(query => \"Perl\");\nuse LWP::UserAgent;\n$ua = LWP::UserAgent->new;\n$response = $ua->request($form->click);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 228,
                "subsections": []
            },
            {
                "name": "INPUTS",
                "lines": 122,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "HTML::Form - Class that represents an HTML form element\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 6.07\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use HTML::Form;\n$form = HTML::Form->parse($html, $baseuri);\n$form->value(query => \"Perl\");\n\nuse LWP::UserAgent;\n$ua = LWP::UserAgent->new;\n$response = $ua->request($form->click);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Objects of the \"HTML::Form\" class represents a single HTML \"<form> ... </form>\" instance. A form\nconsists of a sequence of inputs that usually have names, and which can take on various values.\nThe state of a form can be tweaked and it can then be asked to provide HTTP::Request objects\nthat can be passed to the request() method of LWP::UserAgent.\n\nThe following methods are available:\n\n@forms = HTML::Form->parse( $htmldocument, $baseuri )\n@forms = HTML::Form->parse( $htmldocument, base => $baseuri, %opt )\n@forms = HTML::Form->parse( $response, %opt )\nThe parse() class method will parse an HTML document and build up \"HTML::Form\" objects for\neach <form> element found. If called in scalar context only returns the first <form>.\nReturns an empty list if there are no forms to be found.\n\nThe required arguments is the HTML document to parse ($htmldocument) and the URI used to\nretrieve the document ($baseuri). The base URI is needed to resolve relative action URIs.\nThe provided HTML document should be a Unicode string (or US-ASCII).\n\nBy default HTML::Form assumes that the original document was UTF-8 encoded and thus encode\nforms that don't specify an explicit *accept-charset* as UTF-8. The charset assumed can be\noverridden by providing the \"charset\" option to parse(). It's a good idea to be explicit\nabout this parameter as well, thus the recommended simplest invocation becomes:\n\nmy @forms = HTML::Form->parse(\nEncode::decode($encoding, $htmldocumentbytes),\nbase => $baseuri,\ncharset => $encoding,\n);\n\nIf the document was retrieved with LWP then the response object provide methods to obtain a\nproper value for \"base\" and \"charset\":\n\nmy $ua = LWP::UserAgent->new;\nmy $response = $ua->get(\"http://www.example.com/form.html\");\nmy @forms = HTML::Form->parse($response->decodedcontent,\nbase => $response->base,\ncharset => $response->contentcharset,\n);\n\nIn fact, the parse() method can parse from an HTTP::Response object directly, so the example\nabove can be more conveniently written as:\n\nmy $ua = LWP::UserAgent->new;\nmy $response = $ua->get(\"http://www.example.com/form.html\");\nmy @forms = HTML::Form->parse($response);\n\nNote that any object that implements a decodedcontent(), base() and contentcharset()\nmethod with similar behaviour as HTTP::Response will do.\n\nAdditional options might be passed in to control how the parse method behaves. The following\nare all the options currently recognized:\n\n\"base => $uri\"\nThis is the URI used to retrieve the original document. This option is not optional ;-)\n\n\"charset => $str\"\nSpecify what charset the original document was encoded in. This is used as the default\nfor acceptcharset. If not provided this defaults to \"UTF-8\".\n\n\"verbose => $bool\"\nWarn (print messages to STDERR) about any bad HTML form constructs found. You can trap\nthese with $SIG{WARN}. The default is not to issue warnings.\n\n\"strict => $bool\"\nInitialize any form objects with the given strict attribute. If the strict is turned on\nthe methods that change values of the form will croak if you try to set illegal values\nor modify readonly fields. The default is not to be strict.\n\n$form->pushinput( $type, \\%attr, $verbose )\nThis method adds additional inputs to the form. The first argument is the type of input\n(e.g. hidden, option, etc.). The second argument is a reference to a hash of the input\nattributes. The third argument is optional, and will issue warnings about unknown input\ntypes.\n\nExample:\n\npushinput( 'hidden', {\nname  => 'NewFormElement',\nid    => 'NewFormElementId',\nvalue => 'some value',\n});\n\n$method = $form->method\n$form->method( $newmethod )\nThis method is gets/sets the *method* name used for the HTTP::Request generated. It is a\nstring like \"GET\" or \"POST\".\n\n$action = $form->action\n$form->action( $newaction )\nThis method gets/sets the URI which we want to apply the request *method* to.\n\n$enctype = $form->enctype\n$form->enctype( $newenctype )\nThis method gets/sets the encoding type for the form data. It is a string like\n\"application/x-www-form-urlencoded\" or \"multipart/form-data\".\n\n$accept = $form->acceptcharset\n$form->acceptcharset( $newaccept )\nThis method gets/sets the list of charset encodings that the server processing the form\naccepts. Current implementation supports only one-element lists. Default value is \"UNKNOWN\"\nwhich we interpret as a request to use document charset as specified by the 'charset'\nparameter of the parse() method.\n\n$value = $form->attr( $name )\n$form->attr( $name, $newvalue )\nThis method give access to the original HTML attributes of the <form> tag. The $name should\nalways be passed in lower case.\n\nExample:\n\n@f = HTML::Form->parse( $html, $foo );\n@f = grep $->attr(\"id\") eq \"foo\", @f;\ndie \"No form named 'foo' found\" unless @f;\n$foo = shift @f;\n\n$bool = $form->strict\n$form->strict( $bool )\nGets/sets the strict attribute of a form. If the strict is turned on the methods that change\nvalues of the form will croak if you try to set illegal values or modify readonly fields.\nThe default is not to be strict.\n\n@inputs = $form->inputs\nThis method returns the list of inputs in the form. If called in scalar context it returns\nthe number of inputs contained in the form. See \"INPUTS\" for what methods are available for\nthe input objects returned.\n\n$input = $form->findinput( $selector )\n$input = $form->findinput( $selector, $type )\n$input = $form->findinput( $selector, $type, $index )\n@inputs = $form->findinput( $selector )\n@inputs = $form->findinput( $selector, $type )\nThis method is used to locate specific inputs within the form. All inputs that match the\narguments given are returned. In scalar context only the first is returned, or \"undef\" if\nnone match.\n\nIf $selector is not \"undef\", then the input's name, id, class attribute must match. A\nselector prefixed with '#' must match the id attribute of the input. A selector prefixed\nwith '.' matches the class attribute. A selector prefixed with '^' or with no prefix matches\nthe name attribute.\n\nIf $type is not \"undef\", then the input must have the specified type. The following type\nnames are used: \"text\", \"password\", \"hidden\", \"textarea\", \"file\", \"image\", \"submit\",\n\"radio\", \"checkbox\" and \"option\".\n\nThe $index is the sequence number of the input matched where 1 is the first. If combined\nwith $name and/or $type, then it selects the *n*th input with the given name and/or type.\n\n$value = $form->value( $selector )\n$form->value( $selector, $newvalue )\nThe value() method can be used to get/set the value of some input. If strict is enabled and\nno input has the indicated name, then this method will croak.\n\nIf multiple inputs have the same name, only the first one will be affected.\n\nThe call:\n\n$form->value('foo')\n\nis basically a short-hand for:\n\n$form->findinput('foo')->value;\n\n@names = $form->param\n@values = $form->param( $name )\n$form->param( $name, $value, ... )\n$form->param( $name, \\@values )\nAlternative interface to examining and setting the values of the form.\n\nIf called without arguments then it returns the names of all the inputs in the form. The\nnames will not repeat even if multiple inputs have the same name. In scalar context the\nnumber of different names is returned.\n\nIf called with a single argument then it returns the value or values of inputs with the\ngiven name. If called in scalar context only the first value is returned. If no input exists\nwith the given name, then \"undef\" is returned.\n\nIf called with 2 or more arguments then it will set values of the named inputs. This form\nwill croak if no inputs have the given name or if any of the values provided does not fit.\nValues can also be provided as a reference to an array. This form will allow unsetting all\nvalues with the given name as well.\n\nThis interface resembles that of the param() function of the CGI module.\n\n$form->tryothers( \\&callback )\nThis method will iterate over all permutations of unvisited enumerated values (<select>,\n<radio>, <checkbox>) and invoke the callback for each. The callback is passed the $form as\nargument. The return value from the callback is ignored and the tryothers() method itself\ndoes not return anything.\n\n$request = $form->makerequest\nWill return an HTTP::Request object that reflects the current setting of the form. You might\nwant to use the click() method instead.\n\n$request = $form->click\n$request = $form->click( $selector )\n$request = $form->click( $x, $y )\n$request = $form->click( $selector, $x, $y )\nWill \"click\" on the first clickable input (which will be of type \"submit\" or \"image\"). The\nresult of clicking is an HTTP::Request object that can then be passed to LWP::UserAgent if\nyou want to obtain the server response.\n\nIf a $selector is specified, we will click on the first clickable input matching the\nselector, and the method will croak if no matching clickable input is found. If $selector is\n*not* specified, then it is ok if the form contains no clickable inputs. In this case the\nclick() method returns the same request as the makerequest() method would do. See\ndescription of the findinput() method above for how the $selector is specified.\n\nIf there are multiple clickable inputs with the same name, then there is no way to get the\nclick() method of the \"HTML::Form\" to click on any but the first. If you need this you would\nhave to locate the input with findinput() and invoke the click() method on the given input\nyourself.\n\nA click coordinate pair can also be provided, but this only makes a difference if you\nclicked on an image. The default coordinate is (1,1). The upper-left corner of the image is\n(0,0), but some badly coded CGI scripts are known to not recognize this. Therefore (1,1) was\nselected as a safer default.\n\n@kw = $form->form\nReturns the current setting as a sequence of key/value pairs. Note that keys might be\nrepeated, which means that some values might be lost if the return values are assigned to a\nhash.\n\nIn scalar context this method returns the number of key/value pairs generated.\n\n$form->dump\nReturns a textual representation of current state of the form. Mainly useful for debugging.\nIf called in void context, then the dump is printed on STDERR.\n",
                "subsections": []
            },
            "INPUTS": {
                "content": "An \"HTML::Form\" objects contains a sequence of *inputs*. References to the inputs can be\nobtained with the $form->inputs or $form->findinput methods.\n\nNote that there is *not* a one-to-one correspondence between input *objects* and <input>\n*elements* in the HTML document. An input object basically represents a name/value pair, so when\nmultiple HTML elements contribute to the same name/value pair in the submitted form they are\ncombined.\n\nThe input elements that are mapped one-to-one are \"text\", \"textarea\", \"password\", \"hidden\",\n\"file\", \"image\", \"submit\" and \"checkbox\". For the \"radio\" and \"option\" inputs the story is not\nas simple: All <input type=\"radio\"> elements with the same name will contribute to the same\ninput radio object. The number of radio input objects will be the same as the number of distinct\nnames used for the <input type=\"radio\"> elements. For a <select> element without the \"multiple\"\nattribute there will be one input object of type of \"option\". For a <select multiple> element\nthere will be one input object for each contained <option> element. Each one of these option\nobjects will have the same name.\n\nThe following methods are available for the *input* objects:\n\n$input->type\nReturns the type of this input. The type is one of the following strings: \"text\",\n\"password\", \"hidden\", \"textarea\", \"file\", \"image\", \"submit\", \"radio\", \"checkbox\" or\n\"option\".\n\n$name = $input->name\n$input->name( $newname )\nThis method can be used to get/set the current name of the input.\n\n$input->id\n$input->class\nThese methods can be used to get/set the current id or class attribute for the input.\n\n$input->selected( $selector )\nReturns TRUE if the given selector matched the input. See the description of the\nfindinput() method above for a description of the selector syntax.\n\n$value = $input->value\n$input->value( $newvalue )\nThis method can be used to get/set the current value of an input.\n\nIf strict is enabled and the input only can take an enumerated list of values, then it is an\nerror to try to set it to something else and the method will croak if you try.\n\nYou will also be able to set the value of read-only inputs, but a warning will be generated\nif running under \"perl -w\".\n\n$autocomplete = $input->autocomplete\n$input->autocomplete( $newautocomplete )\nThis method can be used to get/set the current value (if any) of \"autcomplete\" for the\ninput.\n\n$input->possiblevalues\nReturns a list of all values that an input can take. For inputs that do not have discrete\nvalues, this returns an empty list.\n\n$input->otherpossiblevalues\nReturns a list of all values not tried yet.\n\n$input->valuenames\nFor some inputs the values can have names that are different from the values themselves. The\nnumber of names returned by this method will match the number of values reported by\n$input->possiblevalues.\n\nWhen setting values using the value() method it is also possible to use the value names in\nplace of the value itself.\n\n$bool = $input->readonly\n$input->readonly( $bool )\nThis method is used to get/set the value of the readonly attribute. You are allowed to\nmodify the value of readonly inputs, but setting the value will generate some noise when\nwarnings are enabled. Hidden fields always start out readonly.\n\n$bool = $input->disabled\n$input->disabled( $bool )\nThis method is used to get/set the value of the disabled attribute. Disabled inputs do not\ncontribute any key/value pairs for the form value.\n\n$input->formnamevalue\nReturns a (possible empty) list of key/value pairs that should be incorporated in the form\nvalue from this input.\n\n$input->check\nSome input types represent toggles that can be turned on/off. This includes \"checkbox\" and\n\"option\" inputs. Calling this method turns this input on without having to know the value\nname. If the input is already on, then nothing happens.\n\nThis has the same effect as:\n\n$input->value($input->possiblevalues[1]);\n\nThe input can be turned off with:\n\n$input->value(undef);\n\n$input->click($form, $x, $y)\nSome input types (currently \"submit\" buttons and \"images\") can be clicked to submit the\nform. The click() method returns the corresponding HTTP::Request object.\n\nIf the input is of type \"file\", then it has these additional methods:\n\n$input->file\nThis is just an alias for the value() method. It sets the filename to read data from.\n\nFor security reasons this field will never be initialized from the parsing of a form. This\nprevents the server from triggering stealth uploads of arbitrary files from the client\nmachine.\n\n$filename = $input->filename\n$input->filename( $newfilename )\nThis get/sets the filename reported to the server during file upload. This attribute\ndefaults to the value reported by the file() method.\n\n$content = $input->content\n$input->content( $newcontent )\nThis get/sets the file content provided to the server during file upload. This method can be\nused if you do not want the content to be read from an actual file.\n\n@headers = $input->headers\ninput->headers($key => $value, .... )\nThis get/set additional header fields describing the file uploaded. This can for instance be\nused to set the \"Content-Type\" reported for the file.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "LWP, LWP::UserAgent, HTML::Parser\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Gisle Aas <gisle@activestate.com>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This software is copyright (c) 1998 by Gisle Aas.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
                "subsections": []
            }
        }
    }
}