Welcome Guest, Not a member yet? Register   Sign In
Form Validation: Custom Error Messages based on Field?
#1

[eluser]wolfman2000[/eluser]
I do not quite know if this is possible here. In the Form Validation section, it takes about setting custom error messages for both the standard options and callbacks. While that is great, I want something a little different.

One of my form fields has 3 checks on it: overkill perhaps, but work with me. Two are standard checks, and one is a callback. I want it so that if ANY of those checks fail, I have a custom error message to just that field. I don't wish to have to overrule any of the default messages.

If this is not possible...is there a way to call functions such as field_required or field_is_natural_no_zero inside a callback? That could potentially get me what I'm after as well.
#2

[eluser]roj[/eluser]
A quick hack:

If it's a custom check can you not simply include the other 2 function checks within that one custom one?
#3

[eluser]wolfman2000[/eluser]
That is kind of what I'm asking, if there is a way to call those functions. I don't know if you can just do required($var) or valid_email($var) or whathaveyou.
#4

[eluser]skunkbad[/eluser]
You can call a method from the form validation class within your callback, but you should look at the methods in the form validation class and see the arguments they expect. Because the current form validation class doesn't (yet) limit the scope of the methods, you would simple access them by :

$this->form_validation->method_name($arg , $arg, ...);

All of the methods return false or the original value.




Theme © iAndrew 2016 - Forum software by © MyBB