Either type validation in Codeigniter?
I have two controls one dropdown (cmbCategories) and second one input textbox (txtCategory).
Now, I want to add validation. If Category is not selected from cmbCategories dropdown, it will look for txtCategory textbox. If both are not present then it should be given an error just say 'Either you have to select Category from dropdown list 开发者_运维问答or enter into Category textbox'.
I have used following type validation rules but it gives unexpected results.
$this->form_validation->set_rules('cmbCategories','Category','required|is_natural|xss_clean');
$this->form_validation->set_rules('txtCategory','Category','required|min_length[5]|xss_clean');
How I achieve the functionality that I am looking for?
CI's validation methods can only be called on a single input so I don't think that you will be able to use them alone for what you are trying to do. I would just check the post vars that are submitted and make sure that they both aren't empty.
if ($this->input->post('cmbCategories') == 0 && $this->input->post('txtCategory') == '')
{
// set error message and stop processing
}
精彩评论