PHP Classes
elePHPant
Icontem

File: Example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Hatem Mohamed  >  Validation Class  >  Example.php  >  Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: Validation Class
Validate submitted form request values
Author: By
Last change:
Date: 4 years ago
Size: 1,345 bytes
 

Contents

Class file image Download
<?php
/*
 ============================================
FileName : example.php
Author : Hatem Mohamed (http://www.itmideast.com)
Mail : developer-php@hotmail.com
Country : Egypt
Class Name : validation
Date : May 2010
============================================
 */



$POST = array(
           
'name' => 'Fred Scuttle',
           
'age' => 42,
           
'contact_email'=>' fred@example.com',
           
'url'=>'http://phpro.org');

   
/*** 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 ***/
   
$val->addSource($POST);

   
/*** 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 ***/
   
$val->addRules($rules_array);

   
/*** run the validation rules ***/
   
$val->run();

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

   
/*** show the array of validated and sanitized variables ***/
   
print_r($val->sanitized);
?>