PHP Classes

File: system/modules/validation/info.xml

Recommend this page to a friend!
  Classes of Mihajlo Siljanoski  >  Xmodule  >  system/modules/validation/info.xml  >  Download  
File: system/modules/validation/info.xml
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Xmodule
Modular Web application development framework
Author: By
Last change:
Date: 6 years ago
Size: 2,260 bytes


Class file image Download
    <description>This class forms the base class for validation and sanitization of variables from userland. The class provides many standard validation for any type of input from POST, GET, CLI etc. The class accepts input via the addRule method, or will accept and array of rules with the addRules() method.
Upon validation, variables are checked and errors are stored in an errors array while variables that pass validation are stored in the sanitized array. This is ideal if you need to report back errors from input, such as a form, and at the same time, re-populate form fields that have passed validation.
This release adds method chaining to the addRule() method and also provides a trim option to trim variables that are submitted.</description>
        <return>$validation will be an object with methods for validating data.</return>

    $POST = array(
            'name' => 'Fred Scuttle',
            'age' => 42,
            'contact_email'=>'   ',

    /*** an array of rules ***/
    $rules_array = array(
        'name'=>array('type'=>'string',  'required'=>true, 'min'=>30, 'max'=>50, 'trim'=>true),
        'age'=>array('type'=>'numeric', 'required'=>true, 'min'=>1, 'max'=>120, 'trim'=>true));

    /*** a new validation instance ***/
    $val = new validation;

    /*** use POST as the source ***/

    /*** add a form field rule ***/
    $val->addRule('contact_email', 'email', true, 1, 255, true)
        ->addRule('url', 'url', false, 10, 150, false);

    /*** add an array of rules ***/

    /*** run the validation rules ***/

    /*** if there are errors show them ***/
    if(sizeof($val->errors) > 0)

    /*** show the array of validated and sanitized variables ***/
For more information send a message to info at phpclasses dot org.