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 />”;
    }



  • 相关阅读:
    linux常见的基本操作命令
    CentOS-7安装mongodb
    分布式CAP理论
    Spring-boot2.X整合Apache ActiveMQ5.X
    Apche ActiveMQ5.X介绍及CentOS7的安装
    初识Java消息服务JMS
    初始Apache-Shiro权限认证Web知识点
    Java定时任务总结
    Apache-Shiro自定义Realm实战
    Java 作业题1
  • 原文地址:https://www.cnblogs.com/youxin/p/2329678.html
Copyright © 2011-2022 走看看