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)
the following are available rules for get/post/ORM etc..
requiredoptionalintstringtextfloatnumberemailurlleninmatchescontainsregx
requiredoptionalsizeext.allowext.denymime.allowmime.denyname.banname.regximgimg.heightimg.widthcontent.bancontent.lencontent.containsrequired 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)
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"
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
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; //}}
$key the Current form field name$elem the Current Form field's value$k the Index of Current Criteria$v current Criteria So you need to add a case for your criteria too. like case ($v == Z_VLD_RULENAME): //Do Validation stuffs here if(Validation-is-successfull){ $status = true;//Just write this same code to mark the field as Valid }else{ (($mode == Z_VLD_NUMERICAL) ? $status = $k : $status = Z_VLD_RULENAME);//Replace RULENAME with your's } break;
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;
$field_name is the Current form field name$content is the Current Form field's value(Array)$file is the Temporary File Path$name Original File name$size File Size$mime File MIME Type$ext File extension$error error code$r is the Index of Current Criteria$rule is current Criteriacase (($error == 0) && $rule == Z_UPLOAD_RULE_RULENAME): //Do Validation Stuffs here if(validated){ $status = true; }else{ ($mode == Z_UPLOAD_NUMARICAL) ? $status = $r : $status = Z_UPLOAD_RULE_RULENAME; } break;
1.5.6