I'd like to create a validation rule independent of any form field. Is it possible in Codeigniter? As far as I could see in the documentation, the set_rules method wants a form field name as first parameter.
Even so, I tried
$this->form_validation->set_rules('products_count', 'products_count', 'callback_products_count_check');
and this is the callback check
function products_count_check()
{
$user = $this->user_model->get(array(
'id' => $this->session->userdata('user_id')
));
if ( ! empty($user))
{
$kit = $this->kit_model->get(array('id' => $user->kit_id));
if ( ! empty($kit)) {
$products_count = $this->product_model->get(array('user_id' => $user->id, 'count' => TRUE));
if ($products_count >= $kit->max_products) {
$this->form_validation->set_message('products_count_check', lang('products.max_products_reached'));
return FALSE;
}
}
}
return TRUE;
}
The function returns false, but the error message isn't shown.
Any ideas?
Thank you.