NAME
HTML::Object::DOM::Element::Form - HTML Object DOM Form Class
SYNOPSIS
use HTML::Object::DOM::Element::Form;
my $form = HTML::Object::DOM::Element::Form->new ||
die( HTML::Object::DOM::Element::Form->error, "\n" );
VERSION
v0.2.1
DESCRIPTION
This interface represents a <form> element in the DOM. It allows access to—and, in some cases, modification of—aspects of the form, as well as access to its component elements.
INHERITANCE
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Form |
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +----------------------------------+
PROPERTIES
Inherits properties from its parent HTML::Object::DOM::Element
acceptCharset
A string reflecting the value of the form's accept-charset HTML attribute, representing the character encoding that the server accepts.
Example:
<form action="/some/where" accept-charset="utf-8">
<button>Ok</button>
</form>
my $inputs = $doc->forms->[0]->acceptCharset; # utf-8
See also Mozilla documentation
action
A string reflecting the value of the form's action HTML attribute, containing the URI of a program that processes the information submitted by the form.
Example:
var $form = $doc->forms->[0];
$form->action = '/cgi-bin/publish';
See also Mozilla documentation
autocomplete
A string (on
or off
) reflecting the value of the form's autocomplete HTML attribute, indicating whether the controls in this form can have their values automatically populated by the browser.
See also Mozilla documentation
elements
Read-only.
A collection object holding all form controls belonging to this form element.
Example:
<form id="my-form">
<input type="text" name="username">
<input type="text" name="full-name">
<input type="password" name="password">
</form>
my $inputs = $doc->getElementById("my-form")->elements;
my $inputByIndex = $inputs->[0];
my $inputByName = $inputs->username;
Another example:
my $inputs = $doc->getElementById("my-form")->elements;
# Iterate over the form controls
for( my $i = 0; $i < $inputs->length; $i++ )
{
if( $inputs->[i]->nodeName == "INPUT" && $inputs->[i]->type == "text" )
{
# Update text input
$inputs->[i]->value->toLocaleUpperCase();
}
}
Another example:
my $inputs = $doc->getElementById("my-form")->elements;
# Iterate over the form controls
for( my $i = 0; $i < $inputs->length; $i++ )
{
# Disable all form controls
$inputs->[$i]->setAttribute( "disabled", "" );
}
See also Mozilla documentation, StackOverflow question
encoding
A string reflecting the value of the form's enctype HTML attribute, indicating the type of content that is used to transmit the form to the server. Only specified values can be set. The two properties are synonyms.
See also Mozilla documentation
length
Read-only.
A long reflecting the number of controls in the form.
Example:
if( $doc->getElementById('form1')->length > 1 )
{
# more than one form control here
}
See also Mozilla documentation
method
A string reflecting the value of the form's method HTML attribute, indicating the HTTP method used to submit the form. Only specified values can be set.
Example:
$doc->forms->myform->method = 'post';
my $formElement = $doc->createElement("form"); # Create a form
$doc->body->appendChild( $formElement );
say( $formElement->method ); # 'get'
See also Mozilla documentation
name
A string reflecting the value of the form's name HTML attribute, containing the name of the form.
Example:
my $string = form->name;
form->name = $string;
my $form1name = $doc->getElementById('form1').name;
if ($form1name != $doc->form->form1) {
# Browser does not support this form of reference
}
See also Mozilla documentation
noValidate
A boolean value reflecting the value of the form's novalidate HTML attribute, indicating whether the form should not be validated.
See also Mozilla documentation
target
A URL reflecting the value of the form's target HTML attribute, indicating where to display the results received from submitting the form.
Example:
$myForm->target = $doc->frames->[1]->name;
See also Mozilla documentation
METHODS
Inherits methods from its parent HTML::Object::DOM::Element
checkValidity
In perl, this always returns true, or whatever value you would have set.
In JavaScript environment, this returns true if the element's child controls are subject to constraint validation and satisfy those constraints; returns false if some controls do not satisfy their constraints. Fires an event named invalid at any control that does not satisfy its constraints; such controls are considered invalid if the event is not canceled. It is up to the programmer to decide how to respond to false.
See also Mozilla documentation
reportValidity
In perl, this always returns true, or whatever value you would have set.
In JavaScript environment, this returns true if the element's child controls satisfy their validation constraints. When false is returned, cancelable invalid events are fired for each invalid child and validation problems are reported to the user.
Example:
$doc->forms->myform->addEventListener( submit => sub
{
$doc->forms->myform->reportValidity();
}, { capture => 0 });
See also Mozilla documentation
requestSubmit
Requests that the form be submitted using the specified submit button object and its corresponding configuration.
Example:
my $myForm = $doc->querySelector( 'form' );
my $submitButton = $myForm->querySelector( '#main-submit' );
if( $myForm->requestSubmit )
{
if( $submitButton )
{
$myForm->requestSubmit( $submitButton );
}
else
{
$myForm->requestSubmit();
}
}
else
{
$myForm->submit();
}
See also Mozilla documentation
submit
This does nothing and returns undef
under perl environment.
In JavaScript environment, this submits the form to the server.
Example:
$doc->forms->myform->submit();
See also Mozilla documentation
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
Mozilla documentation, Mozilla documentation on form element
COPYRIGHT & LICENSE
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.