我有这段代码:
$update['recipe_name'] = $this->input->post('recipename');
$update['recipe_description'] = $this->input->post('recipedescription');
$update['recipe_instruction'] = $this->input->post('recipeinstruction');
$this->form_validation->set_rules($update['recipe_name'], 'Name of '.$update['recipe_name'], 'trim|required');
$this->form_validation->set_rules($update['recipe_description'], 'Description of '.$update['recipe_name'], 'trim|required');
$this->form_validation->set_rules($update['recipe_instruction'], 'Instruction of '.$update['recipe_instruction'], 'trim|required');
for($count=0;$count<$update['total_ingredients'];$count++)
{
$ingredient_inputs['id'] = $this->input->post('id'.$count);
$ingredient_inputs['name'] = $this->input->post('ingredient'.$count);
$ingredient_inputs['quantity'] = $this->input->post('quantity'.$count);
$ingredient_inputs['measurement'] = $this->input->post('measurement'.$count);
$this->form_validation->set_rules($ingredient_inputs['name'],'Name of '.$ingredient_inputs['name'], 'trim|required');
$this->form_validation->set_rules($ingredient_inputs['quantity'], 'Quantity of '.$ingredient_inputs['name'], 'trim|required|numeric');
$this->form_validation->set_rules($ingredient_inputs['measurement'], 'Measurement of '.$ingredient_inputs['name'], 'trim|required');
$update['ingredients'][$ingredient_inputs['id']] = array('componentname'=>$ingredient_inputs['name'],
'quantity'=>$ingredient_inputs['quantity'],'unit'=>$ingredient_inputs['measurement']);
}
if ($this->form_validation->run() == FALSE)
{
}
我不知道我的代码有什么问题,或者set_rules的循环是否搞乱了。它没有显示任何错误,当我运行验证时它总是错误。
答案 0 :(得分:1)
set_rules()
方法的第一个参数应该是字段的名称,而不是用户输入的字段。