EllisLab/CodeIgniter — pull request #2804 by abdmaster (2014-01-08 19:39:10+00:00)
Title: Added custom error messages functionality for individual fields.

We had global custom error message system using set_message() method. But occasionally we need to have custom error message on a specific rule for individual fields. This PR solves it by passing a 4th associative array in the set_rules() method. If set, it will use these error messages for this specific field when rules errors found.

Example
----

$this->form_validation->set_rules('username','User Name','required|min_length[6]|is_unique[users.username]',array(
'required' => 'You have not given any value at field %s'
));
$this->form_validation->set_rules('email','E-mail','required|is_unique[users.email]',array(
'min_length' => 'Character length too short, minimum {param} char.',
'is_unique' => 'This {field} is already in use.'
));

It is also possible to pass this way:

$validation = array(
'username' => array(
'field' => 'username',
'label' => 'User Name',
'rules' => 'required|min_length[6]|is_unique[users.username]',
'error_msg' => array(
'required' => 'You have not given any value at {field}'
),
),
'email' => array(
'field' => 'email',
'label' => 'E-mail',
'rules' => 'required|is_unique[users.email]',
'error_msg' => array(
'min_length' => 'Character length too short, minimum {param} char.',
'is_unique' => 'This {field} is already in use.'
),
),
);