Home >Backend Development >PHP Tutorial >Use php to verify checkbox validity example code
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 = 'yes'; echo "<input type='checkbox' name='subscribe' value='yes'/> 验证数据"; if (isset($_POST['subscribe'])) { if ($_POST['subscribe'] == $value) { $subscribed = true; } else { $subscribed = false; print '提交的复选框值无效。'; } } else { $subscribed = false; } if ($subscribed) { print '验证有效!'; } else { print '验证无效!'; }
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!