Welcome Guest, Not a member yet? Register   Sign In
Form validation class - creating custom error messages
#1

[eluser]thbt[/eluser]
I find that I'm creating a lot of callback functions just so I can have custom error messages. For example:
Code:
$this->validation->set_message("less_than_limit_1", "The must be less than your spending limit.");
$this->validation->set_message("less_than_limit_2", "This must be less than the amount of a single transaction.");

The callback functions less_than_limit_1 and less_than_limit_2 are exactly the same:

Code:
function less_than_limit_1($str,$max) {
    if(!is_numeric($str)){ return false; }
    return $str <= $max;
}

Obviously I'd like to not have identical callback functions with different names, just so I can have custom error messages. Any way to get around this?
#2

[eluser]srisa[/eluser]
Is it not possible to do it this way?
Code:
$this->validation->set_message("less_than_limit_1", "The must be less than your spending limit.");
$this->validation->set_message("less_than_limit_1", "This must be less than the amount of a single transaction.");

Same callback but different error messages.
#3

[eluser]thbt[/eluser]
But how would CI know which of those two error messages to display if it fails the less_than_limit_1 validation? I think the second set_message would just override the first one.




Theme © iAndrew 2016 - Forum software by © MyBB