Jump to content

codeigniter error triggering


Recommended Posts

Is it possible to trigger form validation error from the Model or Controller to target


used in a form?



$att = array('name'=>'x','class' => 'y', 'id' => 'z'); echo form_open('.../...',$att);?> ....


///////////////model.php or controller.php////////////

function tst(){ ....validation code... then... trigger custom error for the validation_errors() in the view.php



Link to comment
Share on other sites

You can extend the form validation library to make any errors accessible as an array in your controller. 

// MY_Form_validation.php (goes in application/libraries)
class MY_Form_validation extends CI_Form_validation
    public function error_array()
        return $this->_error_array;

Then you can access any errors in your controller and do whatever you want with them.

class Tests extends CI_Controller 
    // Constructor etc. here
    // ...

    public function something()

        // Set validation rules, do other stuff, whatever.

        if ($this->form_validation->run() === FALSE) {
            $errors = $this->form_validation->error_array();
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.