我有簡檔數據的數組我需要驗證:笨:驗證表單陣列不工作
$user_group_profiles = $this->input->post('user_group_profiles', TRUE);
foreach ($user_group_profiles as $key => $user_group_profile)
{
$this->form_validation->set_rules("user_group_profiles[$key][profile_name]", 'Profile Name', 'trim|required');
$this->form_validation->set_rules("user_group_profiles[$key][birthdate]", 'Birthdate', 'trim|required');
// TODO: heigth/weight not required, but the validation somehow makes it required
$this->form_validation->set_rules("user_group_profiles[$key][height]", 'Height', 'trim|greater_than[0]');
$this->form_validation->set_rules("user_group_profiles[$key][weight]", 'Weight', 'trim|greater_than[0]');
}
身高和體重是選項,但是,當沒有設置值這些字段,CI驗證抱怨。 A var_dump($user_group_profiles);
顯示了這一點:
array
'ugp_b33333338' =>
array
'profile_name' => string '' (length=0)
'birthdate' => string '' (length=0)
'height' => string '' (length=0)
'weight' => string '' (length=0)
任何想法可能是什麼錯?
編輯1:
我走進CI的Form_validation庫並取得$_field_data
和公共成員。當我var_export它之後,我得到這個:
'user_group_profiles[ugp_833333338][height]' =>
array
'field' => string 'user_group_profiles[ugp_833333338][height]' (length=42)
'label' => string 'Height' (length=6)
'rules' => string 'greater_than[1]' (length=15)
'is_array' => boolean true
'keys' =>
array
0 => string 'user_group_profiles' (length=19)
1 => string 'ugp_833333338' (length=13)
2 => string 'height' (length=6)
'postdata' => string '' (length=0)
'error' => string 'The Height field must contain a number greater than 1.' (length=54)
'profile_name'和'birthdate'也是空的? – Hindol
是的,我剛剛提交了沒有任何輸入的表單來顯示結構。 – StackOverflowNewbie
我可以看看你的HTML標記嗎? [Pastebin](http://pastebin.com/) – Rocco