I have a custom callback in my codeigniter validation that is not getting called, I just can't figure out where the error is.
This is my controller:
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('pedido', 'numero de pedido', 'trim|required|integer');
$this->form_validation->set_rules('cliente', 'nombre del cliente', 'trim|required|alpha_numeric_spaces');
$this->form_validation->set_rules('motivo', 'motivo de la devolucion', 'trim|required|alpha_numeric_spaces');
$this->form_validation->set_rules('imagen', 'imagen', 'callback_handle_upload');
if ($this->form_validation->run() == FALSE) {
$error_array = array(
'pedido' => form_error('pedido'),
'cliente' => form_error('cliente'),
'motivo' => form_error('motivo'),
'imagen' => form_error('imagen')
);
$this->session->set_userdata('notify', $error_array);
redirect('garantias-y-devoluciones');
die();
}
This is my callback function
public function handle_upload($str)
{
$this->form_validation->set_message('imagen', 'The {field} has an error.');
return FALSE;
}
It should trigger the error but its not.
SOLVED.! If anyone gets this same error, this is how i solve it, it is a bug with HMVC "before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly."
Just add public $CI in you MY_Form_validation
then on your controllers constructor:
$this->load->library('form_validation');
$this->form_validation->CI =& $this;
more info on the following page: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With