开发者

Custom error messages in Codeigniter

开发者 https://www.devze.com 2023-03-12 06:36 出处:网络
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]\');

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

0

精彩评论

暂无评论...
验证码 换一张
取 消