2016-03-14 38 views
0

我有一個這樣的形式:提取值

<input type='text' name='category[]' value='firstcategory'> 
<input type='text' name='category[]' value='secondcategory'> 

像這樣

$this->form_validation->set_rules('category[]', 'Category Name', 'checkcategory'); 

我怎麼能得到firstcategorysecondcategory中值的驗證規則我checkcategory回調?

我嘗試print_r($_POST)後,它給我這樣的:

Array ([category] => Array ([0] => 'firstcategory' [1] => 'secondcategory')) 

因此,爲了達到我想要的,我已經試過這樣的事情在我checkcategory回調:

$neddle = array('firstcategory' => $str['category'][0], 'secondcategory' => $str['category'][1]); 

但它沒有工作。

+0

你可以給他們不同形式的名字 - 做驗證 - ,然後根據需要將它們結合起來?它似乎也將有所幫助,如果有驗證錯誤回聲出來...... – cartalot

回答

0

你還不行。

有這個功能請求將被履行了CodeIgniter的3.1.0:https://github.com/bcit-ci/CodeIgniter/issues/193

+0

其實,我想要做一個驗證過程。在我的數據庫中,我有一個複合唯一鍵,它是一個由兩個字段構成的唯一鍵。我想返回唯一鍵並從用戶提交的數據中獲取數組,然後檢查用戶提交的數組是否是從數據庫返回的數組(複合唯一鍵)的成員。你能指出我的問題的一些線索嗎?我看到你已經解決了很多CI相關的問題。 – Ary

+0

或者用簡單的句子,我想驗證一個複合唯一鍵 – Ary