Php 验证codeigniter中动态生成的字段数组
我有一个表单,其中一些字段是动态生成的Php 验证codeigniter中动态生成的字段数组,php,arrays,codeigniter,validation,jquery,Php,Arrays,Codeigniter,Validation,Jquery,我有一个表单,其中一些字段是动态生成的 <table class="insideform"> <tr> <td> <script> $(document).ready(function() {
<table class="insideform">
<tr>
<td>
<script>
$(document).ready(function() {
$('#addrange').click(function(){
var value = '<tr><td><input type="number" size="10" id="from" name="from[]" value=""></td>';
value += '<td><input type="text" size="10" id="to" name="to[]" value=""></td>';
value += '<td><input type="text" id="disprice" name="disprice[]" /></td>';
value += '<td valign="middle" id="removerange">x</td>';
value += '<td id="to_err" class="err"></td></tr>';
$('.discounttable').append(value);
});
$('body').on("click","#removerange",function(){
$(this).parent().remove();
});
$('#maxqty').change(function(){
var value = $('#maxqty').val() + " Above";
$('#maxabove').text(value);
});
});
</script>
<table class="discounttable">
<tr>
<th>From</th>
<th>To</th>
<th>Price</th>
</tr>
<tr>
<td colspan="2" align="right"><span id="maxabove">10 Above</span></td>
<td><input type="text" name="maxaboveinput" id="maxaboveinput" /></td>
<td id="maxaboveinput_err" class="err"></td>
</tr>
<tr>
<td><input type="text" size="10" id="from" name="from[]" value=""></td>
<td><input type="text" size="10" id="to" name="to[]" value=""></td>
<td><input type="text" /></td>
<td valign="middle" id="removerange">x</td>
<td id="to_err" class="err"></td>
</tr>
</table> <input type="button" name="addrange" id="addrange" value="Add Row"/>
它不会验证我的字段。。。验证错误没有显示任何东西,我试图将其解析为json并回显json代码。。。“to”和“from”在json中显示为空。
有人能帮忙吗?示例控制器:
public function sample_controller() {
if ($this->input->post()) {
$this->load->library('form_validation');
$this->form_validation->set_rules('from[]', 'From field', 'required|xss_clean');
if ($this->form_validation->run() == TRUE) {
echo 'success';
} else {
echo validation_errors();
}
}
$this->load->view('sample_view');
}
示例视图:
<form method="post">
<input type="text" size="10" id="from" name="from[]" value="dino"/>
<input type="text" size="10" id="from" name="from[]" value="babu"/>
<input type="text" size="10" id="from" name="from[]" value="kannampuzha"/>
<input type="submit" value="Go" />
</form>
2) 如果所有文本框都已填充
success
<form method="post">
<input type="text" size="10" id="from" name="from[]" value="dino"/>
<input type="text" size="10" id="from" name="from[]" value="babu"/>
<input type="text" size="10" id="from" name="from[]" value="kannampuzha"/>
<input type="submit" value="Go" />
</form>
The From field field is required.
success