Okay so here is what i'm trying to do I'm making a Form Validation class that works with my Form Generation
and I would like to have default error messages and the ability to have custom error messages so I have
an array that has all the default error messages however certain error messages have a variable that isn't
defined till the validation function is ran so is there a way to have the variable take the value of the defined variable by the function
Default Array:
as you can see minLength and maxLength need $length but $length isn't defined until it is validated like so:PHP Code:class formValidation{
public $rules;
public $error_messages = array(
"alpha" => "This field must contain letters only.",
"numeric" => "This field must contain numbers only.",
"alphaNumeric" => "This field must contain letters and numbers only.",
"minLength" => "This field must contain at least $length characters.",
"maxLength" => "This field can not contain no more than $length characters."
);
public $errors;
PHP Code:private function minLength($field,$length){
if(strlen($field) <= $length){
$this->errors[$field][] = $this->error_messages["minLenght"];
}
}
private function maxLength($field,$lenght){
if(strlen($field) >= $lenght){
$this->errors[$field][] = $this->error_messages["maxLenght"];
}
}


Reply With Quote
Bookmarks