zoukankan      html  css  js  c++  java
  • php处理checkbox

    <input type=”checkbox” id=”imagesonly” name=”imagesonly” value=”yes” />
    <label for=”imagesonly”> Check here if you only want images.</label>


    <?php
    if (isset($_GET[‘imagesonly’]) && $_GET[‘imagesonly’] == ‘Yes’) {
    $imagesonly = ‘Yes‘;
    } else {
    $imagesonly = ‘No‘;
    }
    echo ‘Images Only? ‘ . $imagesonly . ‘<br />’;
    ?>
    <fieldset>
    <legend>where do you live?</legend>
    <input type="checkbox" id="arearural" name="areatypes[]" value="rural"/>
    <label for="arearural">Rural </label>
    <input type="checkbox" id="areasuburb" name="areatype[]" value="suburb"/>
    <label for="areasuburb">Suburb</label>
    <input type="checkbox" id="areacity" name="areatypes[]" value="city"/>
    <label for="areacity">City </label>
    </fieldset>

      In the example you also had a group of checkboxes that you want to process as an array. You signifi
    ed this by using the same name and suffi xing the name with square brackets. Because the checkboxes
    are sent only if they are checked, you use isset() to see if any of the areatype checkboxes
    were selected at all. Then you loop through and fi lter each element of the array and build the fi ltered
     $areatypes array that you will display. See Figure 11-7 for the results.

    if (isset($_GET[‘areatypes’])) {
    $inputs = array();
    $inputs = $_GET[‘areatypes’];
    foreach ($inputs as $input) {
    $areatypes[] = filter_var($input, FILTER_SANITIZE_STRING);
    }
    foreach ($areatypes as $areatype) {
    echo $areatype . ‘<br />’;
    }
    } else {
    echo “You don’t want to live anywhere.<br />”;
    }



  • 相关阅读:
    HTTP Caching
    有关缓存的那些事 读 PHP高级编程
    用embercli 学习搭建了todoMVC
    redis数据结构开篇
    linux最小安装后进行的操作
    redis数据结构整数集合
    redis数据结构动态字符串(SDS)
    redis数据结构压缩列表
    redis数据结构字典
    redis数据结构跳跃表
  • 原文地址:https://www.cnblogs.com/youxin/p/2329678.html
Copyright © 2011-2022 走看看