How can I detect unchecked checkbox with php?

前端 未结 3 1396
失恋的感觉
失恋的感觉 2020-12-20 03:18

There are 3(I do not know how many would be it changeable. 3 only example) checkboxes in my form and I want to detect unchecked checkboxes with php when it post. How can I d

3条回答
  •  北海茫月
    2020-12-20 04:08

    You can do this check entirely in PHP with the following function:

    function cbToBool($cb = true) {
        if (isset($cb)) {
            return true;
        } else {
            return false;
        }
    }
    

    using it like this

    $_POST["blocked"] = cbToBool($_POST["blocked"]);
    

提交回复
热议问题