• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation: Custom Error Messages based on Field?

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.

A quick hack:

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

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.

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.