Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lets you customize the error messages. #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ class MY_Model extends CI_Model
* as validation rules passed to the Form_validation library.
*/
protected $validate = array();

/**
* An array of validation rules message. The format is
* protected $validate_messages = array(
array(
'rule'=> 'required',
'message' => '{field} is required. Please insert de text'),
array(
'rule'=> 'greater_than',
'message' => '{field} bla bla bla bla'));
*/
protected $validate_messages = array();

/**
* Optionally skip the validation. Used in conjunction with
Expand Down Expand Up @@ -821,7 +833,9 @@ public function validate($data)
if(is_array($this->validate))
{
$this->form_validation->set_rules($this->validate);

foreach ($this->validate_messages as $validate_message) {
$this->form_validation->set_message($validate_message['rule'], $validate_message['message']);
}
if ($this->form_validation->run() === TRUE)
{
return $data;
Expand Down