简体   繁体   English

Php 提交表单复选框与复选框

[英]Php submit form checkbox with checked box

I have a db where read all information I read a optino and the stato 1 is confirmed and 0 not... I create a table where anyone can update, check or remove check and after the submit I update all data but in the submit I see only the "checked"... the other not..我有一个数据库,其中读取了所有信息只看到“已检查”......其他没有......

$c_row = current($row);

if ($y > 1) {
    echo "<form name=salvo method=post action='dettaglio.php?tipo=1'>";

    $id = substr($c_row,0,strpos($c_row, '|'));
    $stato = substr($c_row,strpos($c_row, '|')+1,1);

    echo "<td class='tg-dett' align=center>";

    if ($stato == 1) {
        echo "<input type='checkbox' name='chkColor[]' value='$c_row' checked>";
    } else {
        echo "<input type='checkbox' name='chkColor[]' value='$c_row' >";
    }

    echo "</td>";

    for($i = 0; $i < count($_POST["chkColor"]); $i++)
    {
        if(trim($_POST["chkColor"][$i]) != "") {
            echo "chkColor $i = ".$_POST["chkColor"][$i]."<br>";
        }
    }
}

the output is only checked, If anyone remove a check don't appear to output仅检查 output,如果有人删除检查,则不会出现在 output

You can either check on the values after posting it on being empty or not set.您可以在将其发布为空或未设置后检查值。 Or you can use the hidden input trick like so:或者您可以像这样使用隐藏的输入技巧:

<input type='hidden' name='chkColor[' . $row["id"] . ']' value='0'><input type='checkbox' name='chkColor[' . $row["id"] . ']' checked>

This way it will post all boxes but will add a different value to determine which is on and which is not on.这样,它将发布所有框,但会添加一个不同的值来确定哪个打开,哪个没有打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM