PHP表单复选框数组

时间:2016-06-20 09:10:53

标签: php html arrays forms

我有以下HTML表单:

__invoke

将此表单提交给PHP时,我会这样做:

<input type="checkbox" name="markpaid[]">
<input name="paymentdate[]" value="$paymenttodaydate" type="text">

结果总是包含第一个数组。我想只获取$ paymentdate值,并选中相应的复选框。

任何提示?

由于

3 个答案:

答案 0 :(得分:0)

foreach($_POST['markpaid'] as $value) {
echo ($value);
}
如果::

,也可以在POST中尝试使用markpaid []

答案 1 :(得分:0)

我最终得到了:

HTML

<input type="checkbox" name="markpaid[] value="$due->poreceivedid">
<input name="paymentdate-$due->poreceivedid" value="$paymenttodaydate" type="text">

PHP

$markpaid = $this->input->post('markpaid[]');
for ($i=0;$i<count($markpaid);$i++) {
   $paymentdate = $this->input->post('paymentdate-'.$markpaid[$i].'');
}

感谢@Epodax,@ abhishek-gurjar,@ ukhayp提示

答案 2 :(得分:-1)

从下方删除[]

 $markpaid = $this->input->post('markpaid[]');
 $paymentdate = $this->input->post('paymentdate[]');

这将是:

 $markpaid = $this->input->post('markpaid');
 $paymentdate = $this->input->post('paymentdate');

现在$markpaid$paymentdate将为您提供包含所选复选框值的数组。

<强> Reference