Jump to content

codeigniter error triggering


GD77

Recommended Posts

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

validation_errors();

used in a form?

Ex:

///////////////view.php////////////

$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
https://forums.phpfreaks.com/topic/276762-codeigniter-error-triggering/
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()
    {
        $this->load->library('form_validation');

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

        if ($this->form_validation->run() === FALSE) {
            $errors = $this->form_validation->error_array();
        }
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.