GD77 Posted April 10, 2013 Share Posted April 10, 2013 Is it possible to trigger form validation error from the Model or Controller to targetvalidation_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 ///////////////////////////////////////////////////// Quote Link to comment https://forums.phpfreaks.com/topic/276762-codeigniter-error-triggering/ Share on other sites More sharing options...
codebyren Posted April 10, 2013 Share Posted April 10, 2013 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(); } } } Quote Link to comment https://forums.phpfreaks.com/topic/276762-codeigniter-error-triggering/#findComment-1423982 Share on other sites More sharing options...
Mahngiel Posted April 11, 2013 Share Posted April 11, 2013 You don't need to extend the validation class to do this. Just utilize the validation class normally. example usage (the form_validation lib is autoloaded in this app) Quote Link to comment https://forums.phpfreaks.com/topic/276762-codeigniter-error-triggering/#findComment-1424056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.