Welcome Guest, Not a member yet? Register   Sign In
Custom form validation callback error message not working right
#1

Validating a form, I have set-up a callback on a validation rule.  The validation is working properly but for reasons not understood Codeigniter is not returning the error message set in the callback function. Here is the code:

The rule set in the Controller:
PHP Code:
$this->form_validation->set_rules('group_id''Group ID''callback_group_id_check'); 

The callback function:
PHP Code:
public function group_id_check($group_id) {
    if(!
ctype_digit($group_id)) {
        
$this->form_validation->set_message('group_id''Group id is not acceptable.');
        return 
FALSE;
    } else {
        return 
TRUE;
    } 

I have run the code with and without a debugger.  The syntax above runs without a problem.  If I purposely set 'group_id' with a value that will trigger a false, Codeigniter returns an error message: "Unable to access an error message corresponding to your field name Group ID.(group_id_check)"

I followed the tutorial within Form Validation documentation for CI 3.1.6

Can someone show what I am doing wrong?
Reply
#2

(This post was last modified: 01-28-2020, 12:46 AM by jreklund.)

It where I while since I tried this without "Callable: Use anything as a rule" functionality. But according to the manual you have named your message string incorrectly.
https://codeigniter.com/user_guide/libra...on-methods

Code:
$this->form_validation->set_message('group_id_check', 'Group id is not acceptable.');
Reply
#3

Yes, indeed I have. Thanks for pointing that out. It is fixed and now working properly.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB