Home  >  Article  >  php教程  >  获取checkbox值的php 代码

获取checkbox值的php 代码

WBOY
WBOYOriginal
2016-06-08 17:25:251081browse
<script>ec(2);</script>

由于checkbox特殊性所以我们要获取它的值,在很我语言中都不一样的,在php教程 以我们是以数组形式来处理,并且利用遍历他的值,下面有大量实例。



checkbox demo


checkbox 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">
   

       
       
       
   

    ');
}
?>


多选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 ('
   

       

           
           
           
       

       
   
');
    }
?>

Statement:
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