php - Custom validation in codeigniter 3 -


one thing don't codeigniter validation logic being inside controller, increasing , messing code. in order separate logic controller, i've created model imports form_validation library:

class bs_validator extends ci_model  {      protected $rules = array();      protected $fields = array();      # keys of fields.     public function getstructure()     {         return array_keys( $this->fields );     }      # validate $_post against rules , fields.     public function validate()     {         $this->load->library('form_validation');          foreach( $this->rules $key => $rule )         {             $this->form_validation->set_rules( $key, $this->fields[$key], $rule );         }          return $this->form_validation->run( $this );     } } 

for each validation extend class:

class user_create extends bs_validator {     protected $fields = array(         'name' => 'nome',         'email' => 'email',         'password' => 'senha',         'password_repeat' => 'repetir senha'     );      protected $rules = array(         'name' => 'required|min_length[3]|max_length[50]',         'email' => 'required|min_length[8]|max_length[100]|valid_email|is_unique[users.email]',         'password' => 'required',         'password_repeat' => 'required|callback_password_repeat_check'     );      public function password_repeat_check ($password_repeat)     {         return true;     } } 

everything works charm, except custom validation method, never called. in specific case, returns (pasword_repeat_check) error.

what should method recognized?

you can define callback this

just replace there. hope you

 'password_repeat' => 'required|',                         function($password_repeat) {                          //your conditon                           return true;                      } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -