dongqing4070 2018-03-24 07:20
浏览 6
已采纳

选中复选框后如何将用户发送到不同的页面?

<form entype="multipart/form-data" method="GET" action="">
          <div class="box-body">
            <input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
          </div>
          <div class="box-body">
            <input value="1" type="checkbox" class="minimal" name="queryexp" />
            Gunakan query expansion
          </div>
          <div class="box-footer">
            <button type="submit" class="btn btn-primary" value="Submit">Submit</button>
          </div>
        </form>

Hi hello I want to ask a simple question. The code above is search.php, I want to send the form to a different page based on if the checkbox is checked or not. If the checkbox is checked it will be directed to resqueryexp.php, but if not it will be directed to result.php

I have been trying to adding this code but it doesn't work.

<?php

if (isset($_GET['queryexp'])){

    header("Location: resqueryexp.php");

}else{

   header("Location: result.php");
}?>

Sorry for my bad English and Thanks in advance.

  • 写回答

2条回答 默认 最新

  • duanpu1963 2018-03-24 07:55
    关注

    <?php
    if ( isset( $_GET['submit'] )) {
      if ($_GET['queryexp'] == 1 ){
         header("Location: resqueryexp.php");
         exit;
    }
    else 
    {
         header("Location: result.php");
         exit;
      }
    }   
    ?>
    <html>
    <head><title>test</title>
    </head>
    <body>
        <form enctype="multipart/form-data" method="GET" action="">
                  <div class="box-body">
                    <input class="form-control input-lg" name="keyword" type="text" placeholder="Masukkan kata kunci">
                  </div>
                  <div class="box-body">
                    <input value="1" type="checkbox" class="minimal" name="queryexp" />
                    Gunakan query expansion
                  </div>
                  <div class="box-footer">
                    <button type="submit" name="submit" class="btn btn-primary" value="Submit">Submit</button>
                  </div>
                </form>

    This code won't run here at SO, but this is how it may work on your webserver. The important part is to test if the form was submitted. So, in this case, I gave the submit button the name of "submit" and then tested with PHP to see if the form was even submitted. If the form is submitted and if the checkbox is checked, the redirect via header() occurs. Otherwise, if the checkbox is unchecked, then the redirect occurs via header to result.php. You may avoid header issues by making an adjustment to you PHP.ini settings and adding this line "output_buffering = On".

    Note: usually a form with the enctype attribute having a value of "multipart/form-data" involves submitting a file and under such circumstances the method attribute should be a POST request instead of a GET; see MDN.

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算