0

I created My_Form_validation class that extends from CI_Form_validation class.

I created a custom method to validate alpha strings with withe spaces, and work properly. But, now i need validate if an id exists in the database.

So i created a method in My_Form_validation to check it, but not work, the validation always return false:

My_Form_validation

class My_Form_validation extends CI_Form_validation { public function get_error_array(){ return $this->_error_array; } public function alpha_space($value){ $str = str_replace(" ", "", $value); return ctype_alpha($str); } public function entity_exist($id){ return true; } } 

Validation rule

'entity_report' => array( array( 'field' => 'id', 'label' => 'id', 'rules' => 'trim|required|is_natural_no_zero|entity_exist' ) ) 

Why Codeigniter not catch the validator from the validation class ? I dont want the validator method in a controller.

Any ideas ?

2 Answers 2

0

I think the problem with that you not make instance of CI

function __construct() { parent::__construct(); // reference to the CodeIgniter super object $this->CI =& get_instance(); } 

And set your validation rules like

$this->CI->form_validation->set_message('email_check', 'The %s is not valid.'); 
Sign up to request clarification or add additional context in comments.

Comments

0
You can Use like this create form_validation.php file in config folder. $config = array( 'entity_report' => array( array( 'field' => 'id', 'label' => 'ID', 'rules' => 'required|min_length[2]' ) ) ); insert this line in autoload.php $autoload['config'] = array('form_validation'); if ($this->form_validation->run('entity_report') == FALSE) { Your code here. } else { your code here. } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.