I'm building a reservation system where the user first selects how many persons, and then depending on that selection, ajax will populate the respective number of text input fields to get the name of the guests.

So my stripped down text input structure is such:

<input type="text" name="name[]" value="<?php echo set_value('name[]');?>"/>
<input type="text" name="name[]" value="<?php echo set_value('name[]');?>"/>
<input type="text" name="name[]" value="<?php echo set_value('name[]');?>"/>

And on my controller, the validate function is such:

$this->load->library('form_validation');   
$this->form_validation->set_rules('name[]', 'Name', 'required|xss_clean');

So the thing that isn't working right is on submit, if I only entered a name on input 1, on the validated page, the errors will show for every input, at the same time, every input will have the same name i entered for input #1.

What am I doing wrong here ?

share|improve this question
    
This question is similar to stackoverflow.com/questions/7428775/… (Asked yesterday...) – Carlos Mora Sep 16 '11 at 11:59

Just do it manually

$errors = "";
foreach($name as $n){
    if(!$n){
        $errors .= "Please fill in all names fields";
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.