Custom error messages in Codeigniter
I am trying to set custom error messages for invalid length of the following fields:
$this->form_validation->set_rules('name', 'Name', 'required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');
I want to set custom error messages for both of above fields, for example "Invalid name" and "invalid password".
I am trying following:
$this->form_validation->set_message('min_length', 'Invalid name');
But it will put same error message to both fields ie. 'Invalid na开发者_开发知识库me'. How can I set second message (eg. Invalid Password), to the password field?)
Thanks for help.
From CI user_guide:
If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.
$this->form_validation->set_message('min_length', 'Invalid %s');
%s
will become "password" or "name" or whatever field name the min_length is set
精彩评论