Formatting output Plese Wait...
validationCore Class Reference
validationCore class contains the Common methods and attributes of all types of
validation related classes such as
form validation upload validation etc.
More...
|
Public Member Functions |
| addCriteria ($field_name, $rules=null, $msg=null) |
| Sets the Rules for form validation.
|
| removeCriteria ($field_name, $criteria=null) |
| if a Criteria is specified Removes that specific Criteria else Removes all criterias for that Field Name Supplied
|
| parseCriteria ($map_file) |
| Parses the validation map from an existing config file.
|
| validationStatus () |
| gets a (optional) form field name and returns true if its valid else returns either (if mode is Z_VLD_NUMERICAL) the index of the unmatched rule, or (Z_VLD_TEXTUAL) textuale name e.g.
|
| overrideErrorMsg ($field_name, $err, $err_txt) |
| This method lets you overrite teh error message set for a certain form field for a certain error.
|
| isValid ($key=null) |
| If no arguments given Returns true if all form fields in the form is valid else returns flase If a form field name is given as an arguments returns true if that form field is valid else returns false.
|
| errtext ($field_name) |
| Returns teh error text set for a crtain field for the unmatched criteria.
|
| revalidate () |
| Revalidate everything.
|
Data Fields |
| $rules = array() |
| $res = array() |
| $err |
| $validated = false |
Detailed Description
validationCore class contains the Common methods and attributes of all types of
validation related classes such as
form validation upload validation etc.
Definition at line 30 of file abstract/validation/core.php.
Member Function Documentation
validationCore::addCriteria( string $field_name, mixed $rules = null
, mixed $msg = null
)
Sets the Rules for form validation.
Must have $this->method already set before using it provide the form field name as the forst argument and an array of rules as the second argument.
if $rules is given as string $msg must be a string if a third argument $msg is given as an array it would be assumed that the 2nd argument $rules is an array of rules. If a third argument $msg is given as an String or Intger It would be assumed that 2nd argument is also a string and it would fire Error if its not string if the third argument $msg is not given it would be assumed that $rules array contains the CRITERIA(s) as the key elements and teh error message(s) as the value(s) and if the criteria is not valid it would Fire Error if the $rules array is NUMARICALLY INDEXED It would Fire Error
- Parameters:
-
| $field_name | |
| $rules | |
| $msg | optional |
{$msg is given
Definition at line 51 of file abstract/validation/core.php.
References $rules, and perror().
Referenced by parseCriteria().
Show Source00051 {
00052 if(is_null($msg)){
00053
00054 foreach($rules as $rule => $err_msg){
00055 if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00056 if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00057 array_push($this->rules[$field_name], $rule);
00058 $this->err[$field_name][$rule] = $err_msg;
00059 $this->err[$field_name][] = $err_msg;
00060 }
00061
00062 }else{
00064 if(is_string($msg)){
00065 if(!is_string($rules)){
00066 perror('<code>zigmoyd.validation.core.addCriteria()</code><br />expects $rule to be a string as $msg is given as a string');
00067 }else{
00068 if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00069 if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00070 array_push($this->rules[$field_name], $rules);
00071 $this->err[$field_name][$rules] = $msg;
00072 $this->err[$field_name][] = $msg;
00073 }
00074 }else{
00075 if(is_array($msg)){
00076 foreach($rules as $i => $rule){
00077 if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00078 if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00079 array_push($this->rules[$field_name], $rule);
00080 $this->err[$field_name][$rule] = $msg[$i];
00081 $this->err[$field_name][$i] = $msg[$i];
00082 }
00083 }else{
00084 perror('<code>zigmoyd.validation.core.addCriteria()</code><br />Invalid Datatype of $msg');
00085 }
00086 }
00087
00088 }
00089 }
Top
validationCore::removeCriteria( string $field_name, string $criteria = null
)
if a Criteria is specified Removes that specific Criteria else Removes all criterias for that Field Name Supplied
- Parameters:
-
| $field_name | |
| $criteria | optional |
Definition at line 96 of file abstract/validation/core.php.
References perror().
Show Source00096 {
00097 if(!is_null($criteria)){
00098 foreach($this->rules[$field_name] as $i => $rule){
00099
00100 if(!is_numeric($criteria)){
00101 if($rule == $criteria){
00102 unset($this->rules[$field_name][$i]);
00103 $this->rules[$field_name] = array_values($this->rules[$field_name]);
00104 break;
00105 }
00106 }else{
00107 if($i == $criteria){
00108 unset($this->rules[$field_name][$i]);
00109 $this->rules[$field_name] = array_values($this->rules[$field_name]);
00110 break;
00111 }
00112 }
00113
00114 }
00115
00116
00117
00118 $err_keys = array_keys($this->err[$field_name]);
00119 foreach($err_keys as $current_indx => $current_criteria){
00120 if(strcmp($current_criteria, $criteria) == 0){
00121 break;
00122 }
00123 }
00124
00125 if(is_numeric($current_criteria)){
00126
00127 $indx = $err_keys[$current_indx-1];
00128
00129 }else{
00130
00131 $indx = $err_keys[$current_indx+1];
00132
00133 }
00134
00135 if(!isset($this->err[$field_name][$indx])){
00136 perror('<code>zigmoyd.validation.core.removeCriteria()</code><br />Zigmoyd Internal debug level Error Plese Inform this to Zigmoyd Developers<br />Alternative Index not found<br />on File '.__FILE__.' Class validation near Line '.__LINE__);
00137 }
00138 unset($this->err[$field_name][$current_criteria]);
00139 unset($this->err[$field_name][$indx]);
00140
00141 }else{
00142 foreach($this->rules[$field_name] as $i => $rule){
00143 unset($this->rules[$field_name][$i]);
00144 }
00145 }
00146 }
Top
validationCore::parseCriteria( string $map_file )
validationCore::validationStatus( )
gets a (optional) form field name and returns true if its valid else returns either (if mode is Z_VLD_NUMERICAL) the index of the unmatched rule, or (Z_VLD_TEXTUAL) textuale name e.g.
required of the unmatched rule. if No form field is specified it walks through all the form fields and returns the Index or textual name of the first Unmatched form field depending upon the mode By default mode is set to Z_VLD_NUMERICA and form field name is specified to null.
- Parameters:
-
| $form_field_name | string optional |
| $validation_mode | boolean optional |
- Returns:
- mixed
Definition at line 169 of file abstract/validation/core.php.
References $val, and perror().
Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), isValid(), and revalidate().
Show Source00169 {
00170
00171 if(func_num_args() > 0){
00172 if(func_num_args() > 2){
00173 perror('<code>zigmoyd.validation.core.validationStatus()</code><br /> doesn\'t accepts more than 2 arguments');
00174 }elseif(func_num_args() == 2){
00175
00176 $key = func_get_arg(0);
00177 $mode = func_get_arg(1);
00178 }else{
00179
00180 if(is_string(func_get_arg(0))){
00181 $key = func_get_arg(0);
00182 $mode = Z_VLD_NUMERICAL;
00183 }elseif(is_bool(func_get_arg(0))){
00184 $key = null;
00185 $mode = func_get_arg(0);
00186 }else{
00187 perror('<code>zigmoyd.validation.core.validationStatus()</code><br />Failed understand the arguments given plsese see the manual first');
00188 }
00189 }
00190 }else{
00191 $key = null;
00192 $mode = Z_VLD_NUMERICAL;
00193 }
00194
00195 if($this->validated != $mode){
00196 $this->validate($mode);
00197 }
00198 if(!is_null($key)){
00199 if(!isset($this->res[$key])){
00200 perror('Either No rules Applied on the field `'.$key.'` or '.__CLASS__.'::validationStatus() is being called without calling '.__CLASS__.'::add_criterias() before');
00201 }else{
00202 return $this->res[$key];
00203 }
00204 }else{
00205 foreach($this->res as $key => $val){
00206 if(!is_bool($val)){return $key;}
00207 }
00208 return true;
00209 }
00210 }
Top
validationCore::overrideErrorMsg( string $field_name, mixed $err, string $err_txt )
This method lets you overrite teh error message set for a certain form field for a certain error.
- Parameters:
-
| $field_name | |
| $err | |
| $err_txt | |
Definition at line 218 of file abstract/validation/core.php.
References $err, and perror().
Show Source00218 {
00219 if(!isset($this->rules[$field_name])){
00220 perror("<code>zigmoyd.validation.core.overrideErrorMsg()</code><br />no rule hs been set for The field name $field_name but being used in ");
00221 }else{
00222 $this->err[$field_name][$err] = $err_txt;
00223
00224
00225 $err_keys = array_keys($this->err[$field_name]);
00226 foreach($err_keys as $current_indx => $current_criteria){
00227 if($current_criteria == $err){
00228 break;
00229 }
00230 }
00231
00232 if(is_numeric($err)){
00233
00234 $indx = $err_keys[$current_indx];
00235
00236 }else{
00237
00238 $indx = $err_keys[$current_indx+1];
00239
00240 }
00241
00242 if(!isset($this->err[$field_name][$indx])){
00243 perror('<code>zigmoyd.validation.core.overrideErrorMsg()</code><br />Zigmoyd Internal debug level Error Plese Inform this to Zigmoyd Developers<br />Alternative Index not found<br />on /usr/lib/module/ums/validation.php Class validation near Line '.__LINE__);
00244 }
00245 $this->err[$field_name][$indx] = $err_txt;
00246 }
00247 }
Top
validationCore::isValid( string $key = null
)
If no arguments given Returns true if all form fields in the form is valid else returns flase If a form field name is given as an arguments returns true if that form field is valid else returns false.
- Parameters:
-
- Returns:
- bool
Definition at line 257 of file abstract/validation/core.php.
References validationStatus().
Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), and revalidate().
Show Source00257 {
00258 if($this->validated != Z_VLD_NUMERICAL)$this->validate();
00259 if($key == null){
00260
00261 $ret = true;
00262 foreach($this->res as $v){
00263 if(!is_bool($v)){$ret = false;break;}
00264 }
00265 return $ret;
00266 }else{
00267
00268 if(is_bool($this->validationStatus($key))){return true;}else{return false;}
00269 }
00270 }
Top
validationCore::errtext( string $field_name )
Returns teh error text set for a crtain field for the unmatched criteria.
- Parameters:
-
- Returns:
- string
Definition at line 277 of file abstract/validation/core.php.
References perror().
Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), and revalidate().
Show Source00277 {
00278
00279
00280
00281
00282
00283 if(!isset($this->err[$field_name])){
00284 perror('<code>zigmoyd.validation.core.errtext()</code><br />No error message is set for Field '.$field_name);
00285 }else{
00286 if(!isset($this->rules[$field_name])){
00287 perror('<code>zigmoyd.validation.core.errtext()</code><br />No rule is set for Field '.$field_name.' but being used in ');
00288 }else{
00289 if(is_bool($this->res[$field_name]) && $this->res[$field_name]){
00290 return true;
00291 }else{
00292 if(!isset($this->err[$field_name][$this->res[$field_name]])){
00293 perror("<code>zigmoyd.validation.core.errtext()</code><br /> No Error Message has been set for Error Index ".$this->res[$field_name]." Error Name ".$this->rules[$this->res[$field_name]]);
00294 }
00295 return $this->err[$field_name][$this->res[$field_name]];
00296 }
00297 }
00298 }
00299 }
Top
validationCore::revalidate( )
Field Documentation
validationCore::$rules = array()
validationCore::$res = array()
validationCore::$validated = false
The documentation for this class was generated from the following file: