Home >Backend Development >PHP Tutorial >Use php to verify checkbox validity example code

Use php to verify checkbox validity example code

怪我咯
怪我咯Original
2017-07-11 14:13:561441browse

Checkboxcheckbox is often used in php form submission. This article introduces through examples how PHP determines whether the value in the checkbox checkbox is selected. Friends in need can refer to the examples in this article.

This article introduces two knowledge points to you:

  • How to get the value of the checkbox when submitting a php form

  • phpHow to determine whether the value in the checkbox is selected

Let’s take a look at the code

<?php  
/**  
* 在php中验证复选框的有效性  
*/ 
$value = &#39;yes&#39;;  
echo "<input type=&#39;checkbox&#39; name=&#39;subscribe&#39; value=&#39;yes&#39;/> 验证数据";  

if (isset($_POST[&#39;subscribe&#39;])) {  
    if ($_POST[&#39;subscribe&#39;] == $value) {  
        $subscribed = true;  
    } else {  
        $subscribed = false;  
        print &#39;提交的复选框值无效。&#39;;  
    }  
} else {  
    $subscribed = false;  
}  

if ($subscribed) {  
    print &#39;验证有效!&#39;;  
} else {  
    print &#39;验证无效!&#39;;  
}


The above is the detailed content of Use php to verify checkbox validity example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn