Loading Please wait...

Validation Map

In Zigmoyd Validation is done by validation Maps. Where you specify

like the following one.

[name]
  required: Your Name must not be left blank
  string:   Your Name Must be a String (Invalid Entry)
[age]
  required: You must enter your age
  int:   Your age must be an Integer (Invalid Entry)
Its a validation map for a Form where there is a form field called name and age, we have two validation criteria for each of them and their corresponding error messages. if some form fields are not mapped in the validation Map its marked as optional field.

Standard rules/Criteria

There are different set of criteria(s) for ROM/ORM cause they deals with textual values. and Upload cause Upload deals with File(s).

ROM/ORM Criteria

validation criterias are same in all kind of validation e.g. get/post/ORM etc.. However there are different set of rules for validating file uploads.

the following are available rules for get/post/ORM etc..

Note:
If you have some other criteria(s) with optional criteria that field will be valid if its left blank. But if some value is entered in it. It will be validated for other validation rules.

Upload Criteria

The following are standard rules applicable for File Upload validation Map.

Renaming a Criteria/rule Name

actually all the criteria names are changable. If you don't like the word required and like to use mandatory instead of required you can do that too.

Criteria Names are Project specific. e.g. if you change required to mandatory in one project it will not affect any other project(s)

Renaming ROM/ORM Criteria

all these rule/criteria names are stored in zig.ini.php file in etc directory of your Project's directory.
[validation]
Z_VLD_REQ = "required"
Z_VLD_OPT = "optional"
Z_VLD_INT = "int"
Z_VLD_STRING = "string"
Z_VLD_TEXT = "text"
Z_VLD_FLOAT = "float"
Z_VLD_DECIMAL = "number"
Z_VLD_EMAIL = "email"
Z_VLD_URL = "url"
Z_VLD_LEN = "len"
Z_VLD_IS = "in"
Z_VLD_MATCH = "matches"
Z_VLD_CONT = "contains"
Z_VLD_REGX = "regx"
You can just change a rule name here. e.g. change required to mandatory in this file.

Renaming Upload Criteria

all these rule/criteria names are stored in upload.ini.php file in etc directory of your Project's directory.
[rule]
Z_UPLOAD_RULE_REQ = "required";required Specifies that the field is mandatory
Z_UPLOAD_RULE_SIZE = "size";size(MIN, MAX) * means any
Z_UPLOAD_RULE_EXT_ALLOW = "ext.allow";ext.allow(png, jpeg) Allowed Extension
Z_UPLOAD_RULE_EXT_DENY = "ext.deny";ext.deny(png, jpeg) Denied Extension
Z_UPLOAD_RULE_MIME_ALLOW = "mime.allow";mime.allow(text/plain|text/html) Allowed Mime Types
Z_UPLOAD_RULE_MIME_DENY = "mime.deny";mime.deny(text/plain|text/html) Denied Mime Types
Z_UPLOAD_RULE_NAME_BAN = "name.ban";name.ban(words1|words2)
Z_UPLOAD_RULE_NAME_REGX = "name.regx";name.regx(REGEX) reguler expression to match
Z_UPLOAD_RULE_IMAGE = "img";img File must be an Image
Z_UPLOAD_RULE_IMAGE_HEIGHT = "img.height";img.height(MIN, MAX) * means any
Z_UPLOAD_RULE_IMAGE_WIDTH = "img.width";img.width(MIN, MAX) * means any
Z_UPLOAD_RULE_CONTENT_BAN = "content.ban";content.ban(words1|words2) Specify Ban words in Contents File must be textual
Z_UPLOAD_RULE_CONTENT_LEN = "content.len";content.len(MIN, MAX) sets the strlen() of a textual file
Z_UPLOAD_RULE_CONTENT_CONTAIN = "content.contains";content.contains(words1|words2) Specify the words must be present on the texual file uploaded
You can just change a rule name here. e.g. change required to mandatory in this file.

Custom Criteria

In Zigmoyd you can also add your own set of custom criteria/rule(s).to do that first write an entry in corresponding INI file and then edit a method validate() of some validation class. and find the switch case in it and add case for your rule too.

Custom criteria for Rom or Orm

First Open etc/zig.ini.php file in your project's directory and search for the [validation] block over there add a new entry at the end of the list. Z_VLD_RULENAME = "rulename" the Z_VLD_RULENAME is a constant that will be used to deal with your rule.

Now Open /usr/lib/module/validation/validation.php and open the validate() method. Scroll to the end of that method. the you will find a switch case. you will find something similar to

//{{ --------- Regexi ----------
case (preg_match('/'.Z_VLD_REGX.'i\((.+)\)/i', preg_quote($v), $m) != 0)://regexi()
  //Match the regex given
  if(eregi($m[1], $elem)){$status = true;}else{(($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_REGX.'i');}
  break;
//}}
//{{ --------- No Rules Matched
default:
  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.'\'');
  $status = $k;
  break;
//}}
Actually Zigmoyd runs a loop on all form fields and their corresponding rules. these are the variables that you will find useful.

Custom Criteria for Upload

First Open etc/upload.ini.php file in your project's directory and search for the [rule] block over there add a new entry at the end of the list. Z_UPLOAD_RULE_RULENAME = "rulename" the Z_UPLOAD_RULE_RULENAME is a constant that will be used to deal with your rule. Now Open /usr/lib/module/upload/upload.php and open the validate() method. Scroll to the end of that method. there you will find a switch case. you will find something similar to
case (($error == 0) && preg_match('/'.preg_quote(Z_UPLOAD_RULE_CONTENT_CONTAIN).'\((\w+)(?:\|(\w+))*\)/', $rule, $m) != 0)://content.contain(passwd|shadow)
  array_shift($m);
  $contents = file_get_contents($file);
  foreach($m as $val){
    if(strstr($contents, $val)){
      $status = true;
      break;
    }
  }
  if(!isset($status)){
    ($mode == Z_UPLOAD_NUMARICAL) ? $status = $r : $status = Z_UPLOAD_RULE_CONTENT_CONTAIN;
  }
  break;
case ($error != 0):
  $status = 'PHP_ERR_'.$error;
  break;
//}}
default:
  perror('Invalid Rule '.$rule.' supplied');
  $status = Z_UPLOAD_RULE_INVALID;
  break;
These are the variables available that you can use.

Generated on Mon Oct 27 23:51:59 2008 for zigmoyd.kdevelop by doxygen 1.5.6