donglanzhan7151 2016-01-10 00:28
浏览 78
已采纳

如何使用PHP + Checkbox禁用/启用我网站的各个部分?

I need help with enableing/disableing parts of my website.

    <p>Disabled Sections:</p>
    <form id="e-d-check" method="post">
        <input type="checkbox" name="SRS" onchange="document.getElementById('e-d-check').submit()">SkiRegionSimulator 2012</input>
        <input type="checkbox" name="Bilder" onchange="document.getElementById('e-d-check').submit()">Bilder</input>
        <input type="checkbox" name="KWS" onchange="document.getElementById('e-d-check').submit()">Klimawandel-Stunde</input>
    </form>

        <table>
            <tr>
                <th>Name</th>
                <th>Größe</th>
                <th>Datum</th>
                <th>Download</th>
            </tr>

            <?php 
                if (isset($_POST['SRS'])) {
                    echo 'Disabled SkiRegionSimulator 2012';
                } else {
                    include'SRS.php';
                }
            ?>

Everytime I uncheck the box it checks itself again...

  • 写回答

2条回答 默认 最新

  • dongling5411 2016-01-10 05:59
    关注

    A different but similar approach with submit onclick.

    <?php 
    $check_SRS = "";
    $check_Bilder = "";
    $check_KWS = "";
    if (isset($_POST['SRS']) && intval($_POST['SRS']) == 1) { $check_SRS = "checked";}
    if (isset($_POST['Bilder']) && intval($_POST['Bilder']) == 1) { $check_Bilder = "checked";}
    if (isset($_POST['KWS']) && intval($_POST['KWS']) == 1) { $check_KWS = "checked";}
    ?>
    <p>Disabled Sections:</p>
       <form id="e-d-check" method="post">
         <input type="checkbox" name="SRS" value="1" onclick="submit()" <?php echo htmlspecialchars($check_SRS); ?>>SkiRegionSimulator 2012</input>
         <input type="checkbox" name="Bilder" value="1" onclick="submit()" <?php echo htmlspecialchars($check_Bilder); ?>>Bilder</input>
         <input type="checkbox" name="KWS" value="1" onclick="submit()" <?php echo htmlspecialchars($check_KWS); ?>>Klimawandel-Stunde</input>
       </form>
    
    <table>
      <tr>
        <th>Name</th>
        <th>Größe</th>
        <th>Datum</th>
        <th>Download</th>
      </tr>
      <?php 
      if (isset($_POST['SRS']) && intval($_POST['SRS']) == 1) {
        echo 'Disabled SkiRegionSimulator 2012';
      } else {
        include'SRS.php';
      }
      ?>
    

    A version of elseif statements to accommodate what are assumed to be the other includes depending on the state of the checkboxes - if one only can be checked:

    <?php
    if(intval($_POST['SRS']) == 1){
       echo 'Disabled SkiRegionSimulator 2012';
    }elseif(intval($_POST['SRS']) != 1){
       include'SRS.php';
    }elseif(intval($_POST['Bilder']) == 1){
       echo 'Disabled Bilder';
    }elseif(intval($_POST['Bilder']) != 1){
       include'Bilder.php';
    }elseif(intval($_POST['KWS']) == 1){
       echo 'Disabled KWS';
    }elseif(intval($_POST['KWS']) != 1){
       include'KWS.php';
    }
    ?>
    

    if more than one can be checked:

     <?php
     if(intval($_POST['SRS']) == 1){
     echo 'Disabled SkiRegionSimulator 2012';
     }else{
     include'SRS.php';
     }
    
     if(intval($_POST['Bilder']) == 1){
     echo 'Disabled Bilder';
     }else{
     include'Bilder.php';
     }
    
     if(intval($_POST['KWS']) == 1){
     echo 'Disabled KWS';
     }else{
     include'KWS.php';
     }
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配