Jac*_*ack 5 html php forms validation codeigniter
这是我的控制器代码来配置规则:
// Previous address(es)
$this->form_validation->set_rules('prev_house_number[]', 'House Number', 'trim|alpha_numeric');
$this->form_validation->set_rules('prev_abode[]', 'Abode', 'trim');
$this->form_validation->set_rules('prev_house_name[]', 'House Name', 'trim');
$this->form_validation->set_rules('prev_address_line_1[]', 'Address Line 1', 'required|trim');
$this->form_validation->set_rules('prev_address_line_2[]', 'Address Line 2', 'trim');
$this->form_validation->set_rules('prev_city[]', 'Town/City', 'required|trim');
$this->form_validation->set_rules('prev_county[]', 'County', 'trim');
$this->form_validation->set_rules('prev_postcode[]', 'Postcode', 'required|max_length[9]|trim');
$this->form_validation->set_rules('prev_country[]', 'Country', 'trim');
$this->form_validation->set_rules('prev_months[]', 'Previous Months', 'trim|integer');
$this->form_validation->set_rules('prev_years[]', 'Previous Years', 'trim|integer');
Run Code Online (Sandbox Code Playgroud)
用户最多可以输入5个以前的地址,如下所示:
地址行1字段后面的代码如下所示:
<div class="input w100 f-left c-none">
<input type="text" class="address_line_1 postcode_prev_address_1" id="prev_address_line_1[]" name="prev_address_line_1[]" value="<?php echo set_value('prev_address_line_1[]');?>"/>
<label for="prev_address_line_1[]">Address Line 1 <span class="required">*</span></label>
</div>
Run Code Online (Sandbox Code Playgroud)
问题在于:假设我输入了5个地址,并且表单上的验证失败,所有五个输入区域将按预期正确地重新填充.但是,CodeIgniter的验证不适用于阵列输入.
这是验证后的直接截图:
正如您所看到的,尽管它使用正确的值重新填充表单,但它不会对它们应用验证规则,并且似乎无法从控制器中识别它们的存在.
我能做什么?
谢谢!
插口
看起来这就是菲尔正在谈论的提交:https://github.com/EllisLab/CodeIgniter/commit/5c561805bd9ae6a4ad5d202277c34a879617b683#system/libraries/Form_validation.php
尝试从表单验证库的开发分支中提取代码,看看它是否可以解决问题。