Reputation: 199
I have this code:
$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)
{
}
I don't know whats wrong with my code or if the looping of set_rules are messing it up. It doesnt show any error, it just always false when i run the validation.
Upvotes: 0
Views: 156
Reputation: 110
The first parameter of set_rules()
method should be the name of the field not what your user entered.
Upvotes: 1