php教程中checkbox值获取,显示,多选值获取
最简单checkbox获取值代码
checkboxdemo
checkbox
demo
demonstrates checkboxes
="handleformcheckbox.php">
="11.00">fries
="chksoda" value ="12.85">soda
="checkbox" name ="chkshake" value ="1.30">shake
=".05">ketchup
="submit">
实例
using default checkboxvalues
$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
type="checkbox" name="food[]" value="mexican" />
chinese
value="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 checkboxvalues
$food =
$_get["food"];
if (!empty($food)){
echo "the foods selected are:
";
foreach($food as $foodstuff){
echo '
/>'.htmlentities($foodstuff);
}
echo
".";
}
else {
echo ('
italian
value="italian" />
mexican
type="checkbox" name="food[]" value="mexican" />
chinese
value="chinese" checked="checked" />
');}
?>