复选框值已损坏


checkbox value broken if statment

我有一个复选框,我正试图使其成为必需的,名称为age_agree

html"是"中的值

然后我的其他表单错误

if(isset($_POST['age_agree']) && $_POST['age_agree'] == 'No') {
                $errors[] = "You must agree you are 18 years of age.";
            }

它不会给出任何错误,但允许框被取消选中

请记住,如果没有选中复选框,它就不会在$_POST中发送到PHP,因此它的实际值几乎无关紧要,您所需要做的就是测试$_POST数组中是否存在这种情况

if( ! isset($_POST['age_agree']) ) {
    $errors[] = "You must agree you are 18 years of age.";
}