Package DE_EPAGES::Presentation::API::Form
This package provides functions for validating input data submitted by HTML forms.
Base |
DE_EPAGES::WebInterface::API::Form |
Example |
my $Form = $Servlet->form; my $hValues = $Form->form( $User, 'LoginData' ); $User->set( $hValues ); # read unchecked values my @Quantities = $Servlet->form->value('Quantity'); # check each individual value my $Index = 0; foreach ( @Quantities ) { unless ( /^\d+$/ ) { $Form->addFormError( { Reason => 'NoInteger', Name => 'Quantity', Index => $Index, LoopName => 'BasketProducts', Form => 'Basket', } ); } $Index++; } # die if an input error occured $Form->executeFormError; |
Functions
- MandatoryForm
- addFormError
- checkValues
- errors
- executeFormError
- existsFormError
- field
- form
- formData
- formErrors
- formName
- locale
- mapFormError
- new
- object
- resetFormErrors
- setlocale
MandatoryForm
Returns TLE variables containging information about the form definition. They can be used to indicate required fields or accepted ranges.
Syntax |
$hVars = MandatoryForm($hFormData); |
Example |
my $hFormData = $self->formData( LoadClassByObject('User', 'LoginData' ) $hVars = { %$hVars, %{ MandatoryForm( $hFormData ) } }; |
Input |
|
Return |
|
addFormError
Adds a form error to the list of form errors. Use formErrors to get all errors that have been added.
Syntax |
$self->addFormError($hFormError); |
Input |
|
checkValues
Checks the form data and converts them from regional-specific formatting to the internal (Perl) representation using the given form field specifications.
Syntax |
$hValues = $self->checkValues($Object, $hFormData, $skipExecuteFormError); |
Example |
my $hFormData = $Form->formData( $Object->class, 'SearchMask' ); my $hValues = $Form->checkValues( $Object, $hFormData ); |
Input |
|
Return |
|
errors
The errors of form vars will be converted to accessable objects.
Syntax |
$hVars = $self->errors; |
Example |
$Servlet->vars('FormError', 1); $Servlet->vars('FormErrors', $self->form->errors); #LOOP(#FormErrors.Errors) Reason: #Reason Name: #Name Value: #Value Index: #Index LoopName: #LoopName <br /> #ENDLOOP #IF(#FormErrors.Reason.FORMAT_NOT_INTEGER) ... #ENDIF |
Return |
|
executeFormError
Throws an 'INVALID_FORM' Error if a form error exists. If $FormError is defined this error will be added and then executed.
Syntax |
$self->executeFormError; $self->executeFormError($FormError); |
Input |
|
existsFormError
Returns true if a form error has been added by addFormError.
Syntax |
$Exists = $self->existsFormError; |
Return |
|
field
Tests form data and converts from external to internal representation.
Syntax |
$Value = $self->field($Object, $FormValue, $hFormData); |
Example |
my $Value = $Servlet->form->field($Shop, $QuantityData, { 'Type'=>'reg_integer', 'Name'=>$InputName }); |
Input |
|
Return |
|
form
Reads form field specifications from the database using the object class and form name. Then checks the form data and converts them to the internal representation using checkValues.
Syntax |
$hValues = $self->form($Object, $FormName, $skipExecuteFormError); |
Example |
my $hValues = $Servlet->form->form($Shop, 'SearchMask'); my $hValues = $Servlet->form->form($Basket, 'Update'); |
Input |
|
Return |
|
formData
Gets form field defininitions from database.
Syntax |
$hFormData = $self->formData( $ObjectClass, $FormName ) |
Example |
$hFormData = $self->formData( LoadClassByAlias('User'), 'LoginData' ) |
Input |
|
Return |
|
formErrors
Returns all form errors that were added previously by addFormError.
Syntax |
$aFormErrors = $self->formErrors; |
Return |
|
formName
Returns the name of the current form.
Syntax |
$FormName = $self->formName; |
Return |
|
locale
Returns the locale that is used for input validation of numbers and date/time values.
Syntax |
$Locale = $self->locale; |
Return |
|
mapFormError
Builds form error from standard error.
Syntax |
$self->mapFormError($hFieldData, $Error); |
Input |
|
new
Creates a form object on a HTTP::Request object.
Syntax |
$Form = DE_EPAGES::Presentation::API::Form->new($HttpRequest); |
Input |
|
Return |
|
object
Returns the object that this form is based on. This object is used to determine format and curreny settings if they are not available otherwise.
Syntax |
$Object = $self->object; |
Return |
|
resetFormErrors
Resets the collected form errors.
Syntax |
$self->resetFormErrors; |
setlocale
Sets the locale that is used for input validation of numbers and date/time values.
Syntax |
$self->setlocale($Locale); |
Input |
|