dqc18251 2014-12-10 11:55
浏览 113
已采纳

在循环中获取多个复选框值

Below is my code

if (!empty($_POST['ok'])) {
    $errorMessage = array();


    $loopcount = 0;
    $i = 0;
    foreach ($_POST['theDate'] AS $i => $theDate) {
        if ($_POST['EW'][$i] == 'EW') {
            $ew = "yes";
        } else {
            $ew = "no";
        }
        $i = $i + 1;

        echo $ew;
    }
}

its pulls the checkbox value of below and assigns it yes or now if value == ew

E/W<input name="EW[]" ID="EW[]" value="EW" type="checkbox" />

the issue is if check these

row  checked
1      no
2      yes
3      no
3      yes

the out result when submitted is

row  checked
1      yes
2      yes
3      no
4      no

It seems to stick anything checked as ew to the top and I don't get why here is a live working example that when submit is clicked echos with output.... all fields need to be filled but is u just add a number i will work

http://runningprofiles.com/tests/addbet.php

  • 写回答

2条回答 默认 最新

  • duanchu2607 2014-12-10 12:02
    关注

    The checkbox is not submitted, if it does not have a value, thus, the 'yes' are the only ones in the loop. the index numbers for that field only from the submitted ones.

    edit - clearification: if not checked - it its value does not get submitted.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图