2011-09-08 38 views
0

我有兩個控件一個下拉(cmbCategories)和第二個輸入文本框(txtCategory)。Codeigniter中的哪種類型驗證?

現在,我想添加驗證。如果未從cmbCategories下拉列表中選擇Category,則它將查找txtCategory文本框。 如果兩者都不存在,那麼應該給出一個錯誤只是說'要麼你必須從下拉列表中選擇類別或輸入到類別文本框'。

我已經使用了下面的類型驗證規則,但它給出了意想不到的結果。

$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'); 

如何實現我,我要找的功能?

回答

0

CI的驗證方法只能在單個輸入中調用,所以我不認爲您可以單獨使用它們來完成您正在嘗試執行的操作。我只是檢查提交的後期變量,並確保它們都不是空的。

if ($this->input->post('cmbCategories') == 0 && $this->input->post('txtCategory') == '') 
{ 
    // set error message and stop processing 
} 
+0

克里斯,你是對的,但我認爲有任何其他的方式... –