表单验证:通过 PHP 的复选框输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15520512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:24:30  来源:igfitidea点击:

Form Validation : Checkbox input through PHP

phpvalidation

提问by Abhinav

Hey I just wanted to know how do we check if a user has checked a checkbox or not in a form after hitting the submit buttom . I am using PHP so any help regarding that would be really appreciated . Thanks

嘿,我只是想知道我们如何检查用户在点击提交按钮后是否选中了表单中的复选框。我正在使用 PHP,因此我们将不胜感激。谢谢

回答by Dead Man

You can do it like this:

你可以这样做:

if(isset($_POST['checkbox_name']) && $_POST['checkbox_name']!="")
{
    echo 'checkbox is checked'; 
}

回答by Mohit Mehta

<input type='checkbox' name='boxname' value='1' />

<?php
    if(isset($_POST['boxname'])
    {
        echo "check box is checked";
    }
?>

回答by advermark

HTML

HTML

<input type='checkbox' name='theName' value='itsChecked'>

PHP

PHP

if($_POST['theName'] == 'itsChecked'){}