Use php to verify checkbox validity example code

怪我咯
Release: 2023-03-13 14:52:01
Original
1371 people have browsed it

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;;  
}
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!