I've got a problem using the form_validation library with CodeIgniter 3.x :
I want to use a model function as a validation rule for an input. When I submit my form, it seems that the function isn't called at all. According to the user guide, here's the way I do it from my controller :
if($this->input->post() !== false)
{
$this->form_validation->set_rules(
'username', //the post value to check
'User Name',
array(
'trim',
'required',
array($this->user_model, 'checkUserName') // i want to call checkUserName from the user_model model
)
);
I don't understand why it doesn't even calls the checkUserName function in the user_model : does anyone has an idea ?
[EDIT] : I saw the source code for the set_rules() function in system/libraries/form_validation.php. It seems that if the third parameter is not a string, it does nothing, so I cannot call a model function. userguide is not uptodate ? Here's the lines of code that I found from form_validation :
// No fields? Nothing to do...
if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
{
return $this;
}
if($this->input->post() !== false)
– Saty