Home : Documentation : Embperl::Form::Validate
Google Web perl.apache.org

 
Home
 
Features
 
Introduction
 
Documentation
 
README
 
README.v2
 
Configuration
 
Embperl
 
Embperl::Object
 
Embperl::Form::Validate
 
Embperl::Syntax
 
Embperl::Recipe
 
Embperl::Mail
 
1.3.6 documentation
 
DBIx::Recordset
 
Installation
 
Download
 
Support
 
Changes
 
Wiki
 
More infos
 
Add info about Embperl
 
Login

    Stable 2.4.0
    Beta 2.5.0_3
Support the development of Embperl! More...
METHODS
[ << Prev: SYNOPSIS ] [ Content ] [ Next: DATA STRUCTURES >> ]

The following methods are available:



$epf = Embperl::Form::Validate -> new ($rules [, $form_id ], [$default_language], [$charset]);top

Constructor for a new form validator. Returns a reference to a Embperl::Form::Validate object.

 

$rules

 

should be a reference to an array of rules, see RULES elsewhere in this document for details.

 

$form_id

 

should be the name (im HTML) or id (in XHTML) parameter of the form tag, which has to be verified.It\'s e.g. used for generating the right path in the JavaScript DOM. It defaults to 'forms[0]' which should be the first form in your page.

 

$default_language

 

language to use when no messages are available in the desired language. Defaults to 'en'.

 

$charset

 

Pass 'utf-8' in case you want utf-8 messages.



$epf->add_rules($field, $field_rules);top

Adds rules $field_rules for a (new) field $field to the validator, e.g.

 $epf->add_rule([ -key => 'fnord', -type => 'Number', -max => 1.3, -name => 'Fnord' ]);

The new rule will be appended to the end of the list of rules.

See RULES elsewhere in this document.



$epf -> validate ([$fdat, [$pref]]);top

Does the server-side form validation.

 

$fdat

 

should be a hash reference to all postend form values. It defaults to %fdat of the current Embperl page.

 

$pref

 

can contain addtional information for the validation process. At the moment the keys language and default_language are recognized. language defaults to the language set by Embperl. default_language defaults to the one given with new.

The method verifies the content $fdat according to the rules given to the Embperl::Form::Validate constructor and added by the add_rule() method and returns an array refernce to error information. If there is no error it returns undef. Each element of the returned array contains a hash with the following keys:

 

key

 

key into $fdat which caused the error

 

id

 

message id

 

typeobj

 

object reference to the Validate object which was used to validate the field

 

name

 

human readable name, if any. Maybe a hash with multiple languages.

 

msg

 

field specific messages, if any. Maybe a hash with multiple languages.

 

param

 

array with parameters which should subsituted inside the message

=pod



$epf -> error_message ($err, [ $pref ])top

Converts one item returned by validate into a error message

 

$err

 

Item returned by validate

 

$pref

 

Preferences (see validate)

=pod



$epf -> validate_messages ($fdat, [ $pref ])top

Validate the form content and returns the error messages as array ref if any. See validate for details.

=pod



$epf -> get_script_code ([$pref])top

Returns the script code necessary to do the client-side validation. Put the result between <SCRIPT> and </SCRIPT> tags inside your page. It will contain a function that is named epform_validate_<name_of_your_form> where <name_of_your_form> is replaced by the form named you have passed to new. You should call this function in the onSubmit of your form. Example:

    <script>
    [+ do { local $escmode = 0 ; $epf -> get_script_code } +]
    </script>

    <form name="foo" action="POST" onSubmit="return epform_validate_foo()">
        ....
    </form>

[ << Prev: SYNOPSIS ] [ Content ] [ Next: DATA STRUCTURES >> ]

© 1997-2012 Gerald Richter / ecos gmbh