3

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 ?

1

1 Answer 1

1

Just do it manually

$errors = "";
foreach($name as $n){
    if(!$n){
        $errors .= "Please fill in all names fields";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.