Categories: Snippets

Setting Error Messages

All of the native error messages are located in the following language file: system/language/english/form_validation_lang.php

To set your own global custom message for a rule, you can either extend/override the language file by creating your own inapplication/language/english/form_validation_lang.php (read more about this in the Language Class documentation), or use the following method:

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

If you need to set a custom error message for a particular field on some particular rule, use the set_rules() method:

$this->form_validation->set_rules('field_name', 'Field Label', 'rule1|rule2|rule3',
        array('rule2' => 'Error Message on rule2 for this field_name')
);

Where rule corresponds to the name of a particular rule, and Error Message is the text you would like displayed.

If you’d like to include a field’s “human” name, or the optional parameter some rules allow for (such as max_length), you can add the {field} and {param} tags to your message, respectively:

$this->form_validation->set_message('min_length', '{field} must have at least {param} characters.');

 

Recent Posts

Sample Contact Form with validation, Captcha & Notification

Contact Controller [crayon-692748b66bdbb225246240/] Contact_form.php - view [crayon-692748b66bdc6122045850/] Contact_model [crayon-692748b66bdca164645837/] Captcha Helper [crayon-692748b66bdd0892566278/] Notifications_model [crayon-692748b66bdd7551813948/] Database…

7 years ago

Delete Files and Execute Database Query remotely

[crayon-692748b66c0ef914450732/] [crayon-692748b66c0f2063292644/]  

7 years ago

Random String Codeigniter

[crayon-692748b66c1cd887106031/] The first parameter specifies the type of string, the second parameter specifies the length.…

7 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-692748b66c261139172930/] 2. Create View File [crayon-692748b66c264742846779/]  

7 years ago

Codeigniter passing 2 arguments to callback – Email validation

[crayon-692748b66c30d104923639/] [crayon-692748b66c30f650305567/]  

7 years ago

CodeIgniter Pagination With Search Demo

Database:- [crayon-692748b66c3dc372962216/] application/model/Pagination_model.php [crayon-692748b66c3df984893356/] application/controllers/Pagination.php [crayon-692748b66c3e1284000582/] application/views/pagination.php [crayon-692748b66c3e4799464275/]  

7 years ago