CodeIgniter Forums
$this->validation->error_string VS validation_errors() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->validation->error_string VS validation_errors() (/showthread.php?tid=15349)



$this->validation->error_string VS validation_errors() - El Forum - 02-02-2009

[eluser]hendrik[/eluser]
In older versions of CI for my login I used $this->validation->error_string to set a custom message when a username + password is in not the db.

Eg. $this->validation->error_string = "Your username and/or password are incorrect.";

In CI 1.7, how do I set a custom error message that is displayed with validation_errors();

Thanks!


$this->validation->error_string VS validation_errors() - El Forum - 02-02-2009

[eluser]JaRoLLz[/eluser]
Excerpt from the user-guide for Form Validation
============
Setting Error Messages

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:
Code:
$this->form_validation->set_message('rule', 'Error Message');

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

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.

In the "callback" example above, the error message was set by passing the name of the function:
Code:
$this->form_validation->set_message('username_check')

You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:
Code:
$this->form_validation->set_message('required', 'Your custom message here');
========


$this->validation->error_string VS validation_errors() - El Forum - 02-02-2009

[eluser]hendrik[/eluser]
But is there any way to assign a custom string (error message) to be displayed when
1) I'm not using a callback to get a message
2) and there is no such rule specified


$this->validation->error_string VS validation_errors() - El Forum - 02-03-2009

[eluser]hendrik[/eluser]
I've found a solution that works for me. The error message is appended to the array that is returned in validation_errors();

Code:
array_push($this->form_validation->_error_array, "My custom message that is unrelated to any rule");



$this->validation->error_string VS validation_errors() - El Forum - 04-20-2009

[eluser]bretticus[/eluser]
[quote author="hendrik" date="1233682938"]I've found a solution that works for me. The error message is appended to the array that is returned in validation_errors();

Code:
array_push($this->form_validation->_error_array, "My custom message that is unrelated to any rule");
[/quote]

Sorry for hijacking this post...

I will more than likely do this. I think it's great that this was so easy to find in the forum. However, I was just wondering if you found a more standard way. I wanted to take a month, day, and year from three drop-downs and check for a valid date. Ant then hook an error into the error array (which is exactly what you do!) Ha. Oh well, I had to ask anyway.