驗證復選框的php代碼,如下:
復制代碼 代碼如下:<?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 '驗證無效!';
}