php开发中如何获取、显示checkbox值的代码实例
checkbox democheckbox demo
demonstrates checkboxes
- fries
- soda
- shake
- ketchup
实例
using default checkbox values$food = $_get[food];
$self = htmlentities($_server['php_self']);
if (!empty($food)) {
echo "the foods selected are:
";
foreach($food as $foodstuf)
{
echo "".htmlentities($foodstuf)."
";
}
}
else
{
echo ("
echo ('method="get">
italian
mexican
chinese
checked="checked" />
');
}
?>
多选checkbox
$options = array('option 1', 'option 2', 'option 3');
$valid = true;
if (is_array($_get['input'])) {
$valid = true;
foreach($_get['input'] as $input) {
if (!in_array($input, $options)) {
$valid = false;
}
}
if ($valid) {
//process input
}
}
?>
实例checkbox多值获取
using default checkbox values$food = $_get["food"];//www.3ppt.com
if (!empty($food)){
echo "the foods selected are: ";
foreach($food as $foodstuff){
echo '
'.htmlentities($foodstuff);
}
echo ".";
}
else {
echo ('
italian
mexican
chinese
');}
?>