CodeIgniter Forums
Form validation class - creating custom error messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form validation class - creating custom error messages (/showthread.php?tid=14206)



Form validation class - creating custom error messages - El Forum - 12-22-2008

[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?


Form validation class - creating custom error messages - El Forum - 12-23-2008

[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.


Form validation class - creating custom error messages - El Forum - 12-23-2008

[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.