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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -