Welcome Guest, Not a member yet? Register   Sign In
Error messages for callable checks in form validation

I'm using codeigniter 3, that lets you use callables instead of callbacks from the controller. But now I have the problem that I can't (don't know how to) send custom messages for this checks in my form, because those rules doesn't have a proper name and therefore I can't use the usual $this->form_validation->set_message('rule_name', 'message');

The code is something like this:

array( function($value){                    
                             // some way to send the message
       return FALSE;

I have checked the code of Form_validation I downloaded from github and I have seen that the only feasible thing that I can do with the anonymous functions is changing the postdata value of the field, something that seems quite interesting but that I don't want to use right now.

So, do you know if there is any way of using callables the same way as callbacks or they only have the use of changing the value of the field? thanks!

CodeIgniter Users Guide

See: FlashData

Yeah, flashdata could save my ass (not a good solution though if I want to use only the validation library), but the problem it's that the callables doesn't work at all as a validation method. I have been looking at the github code and if the result of the method it's a FALSE the system will ignore it and keep looking the next rules, so even if I use flashdata, the form will be considered by codeigniter as valid and won't never show any error message.

I think that the problem, as I see it, it's that the callables are not validators right now, but methods that change the field postdata or do nothing. I have made some minor changes in my fork of Codeigniter and now they also can validate at the cost of adding some verbosity to the callable rules.

Did you report the issue on github?

Yes, I have already done that and sent a link of my way of fixing it (don't have sent pull request because I think that it's a little shabby, but only way I have thought of fixing it), thanks!

Theme © iAndrew 2016 - Forum software by © MyBB