Loading Please wait...

validation Class Reference
[validation.]

Form Validation Class. More...

Inheritance diagram for validation:

Inheritance graph
[legend]
Collaboration diagram for validation:

Collaboration graph
[legend]

Public Member Functions

 validation ($method=null)
 __construct ($method=null)
 Sets the Form Method First argument should be either get or post in any case if no arguments are given it would try to detect the form method.

Data Fields

 $method

Private Member Functions

 validate ($mode=Z_VLD_NUMERICAL)
 validates the form fields from rules array and stores the result in res array

Detailed Description

Form Validation Class.

Definition at line 31 of file usr/lib/module/validation/validation.php.


Constructor & Destructor Documentation

validation::__construct ( method = null  ) 

Sets the Form Method First argument should be either get or post in any case if no arguments are given it would try to detect the form method.

Parameters:
$method string

Reimplemented in zRom_form.

Definition at line 43 of file usr/lib/module/validation/validation.php.

References $GLOBALS, $method, $val, and perror().

00043                                       {
00044     parent::__construct();
00045     if($method == null){
00046       if(isset($GLOBALS['_POST']) && count($GLOBALS['_POST']) > 0){
00047         $this->method = &$GLOBALS['_POST'];
00048       }
00049       elseif(isset($GLOBALS['_GET'])){
00050         $this->method = &$GLOBALS['_GET'];
00051       }
00052     }elseif(is_string($method)){
00053       $this->method = $GLOBALS['_'.strtoupper($method)];
00054     }elseif(is_array($method)){
00055       $this->method = $method;
00056     }elseif(is_object($method)){
00057       //{ Convert object to array
00058       foreach($method as $key => $val){
00059         $this->method[$key] = $val;
00060       }
00061       //}
00062     }else{
00063       perror('<code>zigmoyd.module.validation</code><br />Invalid Argument Supplied datatype '.gettype($method).' not accepted');
00064     }
00065     if(!defined('Z_VLD_NUMERICAL')){define('Z_VLD_NUMERICAL', true);}
00066     if(!defined('Z_VLD_NUMERICAL')){define('Z_VLD_NUMERICAL', true);}
00067     if(!defined('Z_VLD_TEXTUAL')){define('Z_VLD_TEXTUAL', false);}
00068     $this->valid_rules = parse_ini_file(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.'zig.ini.php', true);
00069     $this->valid_rules = $this->valid_rules['validation'];
00070   }

Here is the call graph for this function:


Member Function Documentation

validation::validation ( method = null  ) 

Definition at line 34 of file usr/lib/module/validation/validation.php.

References $method, and zCore::__construct().

00034                                    {
00035     $this->__construct($method);
00036   }

Here is the call graph for this function:

validation::validate ( mode = Z_VLD_NUMERICAL  )  [private]

validates the form fields from rules array and stores the result in res array

Definition at line 76 of file usr/lib/module/validation/validation.php.

References $val, and perror().

00076                                             {
00077     if($mode != Z_VLD_NUMERICAL && $mode != Z_VLD_TEXTUAL){perror('The Mode you specified on adv_valid::validate() is not valid');}
00078     foreach($this->rules as $key => $val){//Looping into form fields in Rules array
00079       $elem = $this->method[$key];
00080       foreach($val as $k => $v){//Looping into rules in rules array
00081         //$key is the Current form field name
00082         //$elem is the Current Form field's value
00083         //$k is the Index of Current Criteria
00084         //$v is current Criteria
00085         //{ --------- Making Rules
00086         switch(true){
00087           //{{  --------- Required ----------
00088           case ($v == Z_VLD_REQ):
00089               (strlen($elem) > 0 && !empty($elem)) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_REQ);
00090             break;
00091           //}}
00092           //{{  --------- Optional ----------
00093           case ($v == Z_VLD_OPT):
00094               (strlen((string)$elem) == 0 || empty($elem)) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_OPT);
00095             break;
00096           //}}
00097           //{{ --------- Integer ----------
00098           case ($v == Z_VLD_INT):
00099               (is_numeric($elem)) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_INT);
00100             break;
00101           //}}
00102           //{{ --------- String ----------
00103           case ($v == Z_VLD_STRING):
00104               (!ctype_digit(trim($elem))) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_STRING);
00105             break;
00106           //}}
00107           //{{ --------- Text ----------
00108           case ($v == Z_VLD_TEXT):
00109               (strlen(trim($elem)) >= 1) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_TEXT);
00110             break;
00111           //}}
00112           //{{ --------- Float ----------
00113           case ($v == Z_VLD_FLOAT):
00114               (ereg('[0-9]+\.[0-9]+', $elem)) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_FLOAT);
00115             break;
00116           //}}
00117           //{{ --------- Number ----------
00118           case ($v == Z_VLD_DECIMAL):
00119               (ereg('[0-9]*[\.]?[0-9]+', $elem)) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_DECIMAL);
00120             break;
00121           //}}
00122           //{{ --------- Email ----------
00123           case ($v == Z_VLD_EMAIL):
00124               (preg_match('~[\w_%-\.]+@(?:[\w-]+)(?:\.[\w]{2,4})+~', $elem) > 0) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_EMAIL);
00125             break;
00126           //}}
00127           //{{ --------- Url ----------
00128           case ($v == Z_VLD_URL):
00129               (preg_match('~(https?|ftp|mms)://(?:\w+@?)?[\w\.\/]{2,}~', $elem) > 0) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_URL);
00130             break;
00131           //}}
00132           //{{ --------- Length ----------
00133           case (preg_match('/'.Z_VLD_LEN.'\((?:\s*)?(\d+)( ?, ?(\d+))?(?:\s*)?\)/', $v, $m) != 0)://len(5, 10) or len(5)
00134               if(isset($m[3])){
00135                 //Starting and ending limits given
00136                 (strlen($elem) >= $m[1] && strlen($elem) <= $m[3]) ?  $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_LEN);
00137               }else{
00138                 //Static Length given
00139                 (strlen($elem) == $m[1]) ? $status = true : (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_LEN);
00140               }
00141             break;
00142           //}}
00143           //{{ --------- Is ----------
00144           case (preg_match('/'.Z_VLD_IS.'\((.+)\)/', $v, $m) != 0):
00145               $m = explode('|', $m[1]);
00146               (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_IS);
00147               foreach($m as $in_key => $in_val){//Looping through expected values list
00148                 if($elem == $in_val){$status = true;break;}
00149               }
00150             break;
00151           //}}
00152           //{{ --------- Match ----------
00153           case (preg_match('/'.Z_VLD_MATCH.'\((.+)\)/', $v, $m) != 0):
00154               if(!isset($this->res[$m[1]])){
00155                 //The Main field Hasnt be validated but Vonfirmation field is being validated
00156                 perror('<code>zigmoyd.validation</code><br />The Confirmation field can not be validated if the Main field is not validated Plese add rule for the Main field first and then for the Confirmation Field');
00157               }else{
00158                 if(is_bool($this->res[$m[1]])){
00159                   //Ok the Main field is validated and is OK
00160                   if($elem == $this->method[$m[1]]){
00161                     $status = true;
00162                   }else{
00163                     (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_MATCH);
00164                   }
00165                 }else{
00166                   //The main field is invalid
00167                   (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_MATCH);
00168                 }
00169               }
00170             break;
00171           //}}
00172           //{{ --------- Contains ----------
00173           case (preg_match('/'.Z_VLD_CONT.'\((.+)\)/', $v, $m) != 0)://contains()
00174               if(strstr($elem, $m[1])){$status = true;}else{(($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_CONT);}
00175             break;
00176           //}}
00177           //{{ --------- Regex ----------
00178           case (preg_match('/'.Z_VLD_REGX.'\((.+)\)/', preg_quote($v), $m) != 0)://regex()
00179               //Match the regex given
00180               if(ereg($m[1], $elem)){$status = true;}else{(($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_REGX);}
00181             break;
00182           //}}
00183           //{{ --------- Regexi ----------
00184           case (preg_match('/'.Z_VLD_REGX.'i\((.+)\)/i', preg_quote($v), $m) != 0)://regexi()
00185               //Match the regex given
00186               if(eregi($m[1], $elem)){$status = true;}else{(($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_REGX.'i');}
00187             break;
00188           //}}
00189           //{{ --------- No Rules Matched
00190           default:
00191             perror('<code>zigmoyd.validation</code><br />No cases aviliable matching the rule `'.$v.'` on Index ('.$k.') applied for the form field `'.$key.'` Which has a value \''.$elem.'\'');
00192             $status = $k;
00193             break;
00194           //}}
00195         }
00196         //}
00197         if($v == Z_VLD_OPT){
00198           if(is_bool($status) && $status){
00199             $this->res[$key] = $status;
00200             break;
00201           }else{
00202             continue;
00203           }
00204         }else{
00205           $this->res[$key] = $status;
00206           if(!is_bool($status) && strlen($status) > 0)break;//Break the Loop
00207         }
00208       }
00209     }
00210     $this->validated = $mode;
00211   }

Here is the call graph for this function:


Field Documentation

validation::$method


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:15 2008 for zigmoyd.kdevelop by doxygen 1.5.6