Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using CodeIngiter 2.1 and I wanna define custom validation errors for each rule per each field. The fields are as follows.

array(
'field' => 'firstname',
'rules' => 'required',
    'error' => 'This field cannot be empty.'
),
array(
'field' => 'email',
'rules' => 'required',
    'error' => 'The email cannot be empty.'
)

But In CodeIgniter only one error message is defined for one rule. So how to override that one and Please suggest some solutions for getting different errors for perticular field. The work is more appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
108 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try using the CI function :

   set_message();

All of the native error messages are located in the following language file:

   language/english/form_validation_lang.php

To set your own custom message you can either edit that file, or use the following function:

   $this->form_validation->set_message('rule', 'Error Message');

for more about set_message here

Hope it will help;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...