diff --git a/core/MY_Model.php b/core/MY_Model.php index 34cb9fe..b4d1c17 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -801,7 +801,7 @@ public function trigger($event, $data = FALSE, $last = TRUE) /** * Run validation on the passed data */ - public function validate($data) + public function validate($data,$partial=null) { if($this->skip_validation) { @@ -810,16 +810,26 @@ public function validate($data) if(!empty($this->validate)) { - foreach($data as $key => $val) - { - $_POST[$key] = $val; - } - + $this->load->library('form_validation'); + $this->form_validation->reset_validation(); + $this->form_validation->set_data($data); #we are not using $_post hacking.. if(is_array($this->validate)) { - $this->form_validation->set_rules($this->validate); + + $config=array(); + + if(!$partial){ + $config = $this->validate;#every rule ablies + }else{ + foreach ($this->validate as $v)if (isset($data[$v['field']]))$config[] = $v;#validate submited forms only + } + + if (empty($config))return $data;#no validation rules for this $data + + + $this->form_validation->set_rules($config); if ($this->form_validation->run() === TRUE) { @@ -890,4 +900,4 @@ protected function _return_type($multi = FALSE) $method = ($multi) ? 'result' : 'row'; return $this->_temporary_return_type == 'array' ? $method . '_array' : $method; } -} \ No newline at end of file +}