Welcome Guest, Not a member yet? Register   Sign In
Form validation message
#1

[eluser]sukuiter[/eluser]
Hi I'm new to codeigniter, today I learn about form validation thing.

I have two callback functions which is identical but doesn't same.
I want those two functions call a custom function for checking.
The custom function is also in the same class as the two functions.

Here's the custom function
Code:
function select_field_check($input, $first_value, $last_value)
    {
        if ($this->form_validation->is_natural_no_zero($input))
        {
            if (!$this->test_library->min_max_check($input, $first_value, $last_value))
            $this->form_validation->set_message('select_field_check', "The %s value must be between $first_value and $last_value");
            
            else
            return TRUE;
        }
        
        else
        $this->form_validation->set_message('select_field_check', 'The %s field must contain a number greater than zero.');
        
        return FALSE;
    }

$input is the value passed to the callback function and then passed to custom function.
$first_value and $last_value are determined by the callback function and then passed to custom function.

I call the custom function in the callback function like this
Code:
return $this->select_field_check($input_year, $first_year, $last_year);

The validation is working but I get this error message.
Code:
Unable to access an error message corresponding to your field name.

I've tried extending the form validation like in this thread but it's still not working.

Does anyone have any idea how to solve the problem? I can validate by setting custom variable or setting callback function individually but if possible I want to do it using callback function.

Thanks..
#2

[eluser]sukuiter[/eluser]
I just solved this problem.. You need to pass the function name to the custom function also.
The problem is because of the rule name must be the same name as the function caller.

Code:
$this->form_validation->set_message($your_rule_name, 'The %s field must contain a number greater than zero.');

Sorry if making this thread cause you trouble.




Theme © iAndrew 2016 - Forum software by © MyBB