Passing checkbox state to PHP

前端 未结 6 1651
南笙
南笙 2021-01-24 22:54


This works fine, ho

6条回答
  •  梦谈多话
    2021-01-24 23:32

    Everything is working normal with your code so far.

    I'm assuming you are creating the hidden field so that 0 is passed to the server when the checkbox is not checked. The problem is that they both get passed when the check box is checked.

    As Death said, the way you should be doing it is with a single checkbox and then checking if the value has been sent to the server or not. That's just how checkboxes work.

    If you want to have a default set then you will have to handle all that on the server side based on weather the checkbox has a value.

    For example:

    $myValue = "";
    if(isset($_POST['check_box_1']))
    {
        $myValue=$_POST['check_box_1'];
    }
    else
    {
        $myValue="0";
    }
    

提交回复
热议问题