4

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.

1
  • Please post solution below as an answer, rather than within your question. Thanks. Commented Nov 10, 2015 at 2:50

4 Answers 4

15

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

Sign up to request clarification or add additional context in comments.

Comments

0

Rename callback method to "handle_upload". For example:

/* ... your code ... */
$this->form_validation->set_rules('imagen', 'imagen', 'callback_handle_upload');
/* ... your code ... */

public function handle_upload($msg){/* your validation code */}

Comments

0

I know it's not always the case but if you are using Ubuntu it's better to check whether you have enabled mod rewrite or not, if not then Apache loads its own files and not the codeigniter->database.php files...

Comments

-1

just rename your callback function to handle_upload. As the in CI doc says To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.

1 Comment

thanks Drixson, I renamed the function as sugested and i get the following "could not access the appropriate error message for the field..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.