Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: set_message for max_length[x]

How do you set an error message for max_length and min_length rules. For instance, if I set a rule max_length[6], I'd like the error message to display Max characters allowed: 5

like image 845
HyderA Avatar asked Sep 10 '26 02:09

HyderA


1 Answers

I got the same problem and even though this post is old, there's no correct answer.. You just have to use the string placeholder %s in second place of your message. In the documentation (http://codeigniter.com/user_guide/libraries/form_validation.html#settingerrors) there is an example for a field not being empty:

$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');

There, it uses the %s placeholder for the name of the field, but if you modify the 'max_length' message putting the field name first and the length second like this:

$this->form_validation->set_message('max_length', 'The field %s max length is %s');

it will work. Is not the best solution, but that one works for me. Hope it helps

like image 112
fankoil Avatar answered Sep 12 '26 01:09

fankoil