开发者

Codeigniter How to Validate Multiple Text Input Array of the Same Name?

I'm building a rese开发者_JS百科rvation 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 ?


Just do it manually

$errors = "";
foreach($name as $n){
    if(!$n){
        $errors .= "Please fill in all names fields";
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜