ePages 6.11.0 - DE_EPAGES/WebInterface/API/Form.pm

Package DE_EPAGES::WebInterface::API::Form

This module is used to parse HTML forms. It recognizes normal web forms (application/x-www-form-urlencoded) and handles file uploads (multipart/form-data). Form data can be submitted by either GET or POST request.

Example
my $Form = DE_EPAGES::WebInterface::API::Form->new( $HttpRequest );
my $UserName = $Form->values->{'user_name'};

Functions

encoding
existsValue
file
files
formValue
formValues
method
new
queryValue
queryValues
value
values

encoding

Returns name encoding of current form. This functions has follings priorities

Syntax
$encoding = $self->encoding;

existsValue

Return 1 if input name exists at post or get parameter.

Syntax
$Exists = $Form->existsValue($InputName);
Input
$InputName (string)
input field name
Return
$Exists (boolean)
form entry exists

file

Returns the content of an uploaded file. Note: uploading files requires the attributes method="post" enctype="multipart/form-data" on the form element.

Syntax
$File = $Form->file($InputName);
Example
my @ProductImages = $Form->file('ProductImage');
my $ProductImage = $Form->file('ProductImage');
Return
$File (string)
uploaded file contents.
In scalar context returns the first file if the form contains
multiple input fields with the same name.
Returns undef if no file input field with the name $InputName exists.
@Files (array of strings)
uploaded file contents

files

Returns the content of all uploaded files as hash reference. Each hash value is an array, because there may be multiple input fields with the same name. Use the values method to get the corresponding file names.

Syntax
$haFiles = $Form->files;
Example
my $Content = $Form->files->{'ProductImage'}->[0];
my $FileName = $Form->values->{'ProductImage'}->[0];
Return
$haFiles (ref.hash.array)
uploaded file contents

formValue

Returns all POST values for a given field name. If the form element is a file-upload element, then the value contains the file name and the content can be determined by the file method.

Syntax
$Value = $Form->formValue($InputName);
@Values = $Form->formValue($InputName);
Example
my @ProductIDs = $Form->formValue('ProductID');
my $ProductID = $Form->formValue('ProductID');
Input
$InputName (string)
input field name
Return
$Value (string)
input field value.
In scalar context returns the first value if the form contains
multiple input fields with the same name.
Returns undef if no input field with the name $InputName exists.
@Values (array of strings)
input field values

formValues

Returns all POST values as hash reference. The values are collected at an array. If the form element is a file-upload element, then the value contains the file name. Use the files method to get the content of the files.

Syntax
$haValues = $Form->formValues;
Example
my @ProductIDs = @{$Form->formValues->{'ProductID'}};
Return
$haValues (ref.hash.array.string)
form values

method

Returns the request method.

Syntax
$Method = $Form->method;
Example
if( $Form->method eq 'POST' ) { ... }
Return
$Method (string)
request method

new

Creates a new Form object from a given HTTP::Request object.

Syntax
$Form = DE_EPAGES::WebInterface::API::Form->new( $HttpRequest );
Input
$HttpRequest (object)
HTTP::Request object
Return
$Form (object)
form object

queryValue

Returns all query string values for a given field name.

Syntax
$Value = $Form->queryValue($InputName);
@Values = $Form->queryValue($InputName);
Example
my $Page = $Form->queryValue('Page');
my @ProductIDs = $Form->queryValue->{'ProductID'};
Input
$InputName (string)
input field name
Return
$Value (string)
input field value.
Returns undef if no input field with the name $InputName exists.
@Values (array of strings)
input field values

queryValues

Returns all query string values as hash reference. The values are collected in an array, if the query string contains multi-valued keys or not.

Syntax
$haValues = $Form->queryValues;
Example
my $Page = $Form->queryValues->{'Page'}->[0];
my @ProductIDs = $Form->queryValues->{'ProductID'};
Return
$haValues (ref.hash.array.string)
query values

value

Returns all POST or GET values for a given field name. If the form element is a file-upload element, then the value contains the file name and the content can be determined by the file method. Form input fields overwrite query-sting parameters.

Syntax
$Value = $Form->value($InputName);
@Values = $Form->value($InputName);
Example
my @ProductIDs = $Form->value('ProductID');
my $ProductID = $Form->value('ProductID');
Input
$InputName (string)
input field name
Return
$Value (string)
input field value.
In scalar context returns the first value if the form contains
multiple input fields with the same name.
Returns undef if no input field with the name $InputName exists.
@Values (array of strings)
input field values

values

Returns all POST or GET values as hash reference, each value is an array of existing input fields. Form input fields overwrite query-sting parameters.

Syntax
$haValues = $Form->values;
Return
$haValues (ref.hash.array)
form values