2014-12-10 11:55
浏览 97


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


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    解决 无用
    打赏 举报
  • doufuxi7093 2014-12-10 12:01

    foreach ($_POST['theDate'] AS $i => $theDate)

    You missing the { at the end

    like this

    foreach ($_POST['theDate'] AS $i => $theDate){

    解决 无用
    打赏 举报

相关推荐 更多相似问题