php - Codeigniter form validate for optional fileds -
i have form fields email , phone.out of these 1 need filled.
$this->form_validation->set_rules('phone[]', 'phone', 'trim|required|xss_clean'); $this->form_validation->set_rules('email[]', 'email', 'trim|required|xss_clean');
how can this?
you need call callbabk function
$this->form_validation->set_rules('phone[]', 'phone', 'trim|xss_clean'); $this->form_validation->set_rules('email[]', 'email', 'trim|xss_clean|callback_check_validation');// call calback
in callback have check empty fields email , phone.
function check_validation() { $phone=$this->input->post('phone'); $email=$this->input->post('email'); if(empty($phone) && empty($email)){// check empty of both filed $this->form_validation->set_message("check_validation", 'atleast phone or email required'); return false; }else { return true; } }
Comments
Post a Comment