有没有办法为下拉菜单提供2个php文件

时间:2019-04-09 23:15:24

标签: php html

我已经使用JavaScript在html中创建了一个下拉菜单。现在,我必须使用PHP。我对PHP不太熟悉,但是我一直在研究并且不断碰碰碰碰。
这是我的代码

  <form action="" method="GET">
  <select name="Choose" id="Choose">
  <option value="generalfeedback"<?php if ($row[Choose] == 
  'generalfeedback') echo ' selected="selected"'; ?>>General 
  Feedback</option>
  <option value="helprequest"<?php if ($row[Choose] == 
  'helprequest') 
  echo ' selected="selected"'; ?>>Help Request</option>
  </select>
  <input type="submit" name="submit" value="Submit" />
  </form>
    <?php
  //loadPage.php
  $requested_page = $_GET['selectedPage'];

  switch($requested_page) {
  case "generalfeedback":
  header("http://cdlwebsysdev.esc- 
  atsystems.net/SRomero/module5/generalfeedback.php");
  break;
  case "helprequest":
  header("http://cdlwebsysdev.esc- 
  atsystems.net/SRomero/module5/helprequest.php");

  }
  ?>
  </body>
  </html>

1 个答案:

答案 0 :(得分:0)

这与您的需求类似。请看看:

<?php
//loadPage.php
if( !empty($_GET['Choose']) ){
    $requested_page = $_GET['Choose'];
    switch($requested_page) {
        case "generalfeedback":
            header("Location: http://cdlwebsysdev.esc-atsystems.net/SRomero/module5/generalfeedback.php");
            //break;
            exit();
        case "helprequest":
            header("Location: http://cdlwebsysdev.esc-atsystems.net/SRomero/module5/helprequest.php");
            //break;
            exit();
    }
}
?><!DOCTYPE html>
<html lang="en">
<head>
<!--Resource Files (if any)-->
</head>
<body>
    <form action="" method="GET">
        <select name="Choose" id="Choose">
            <option value="generalfeedback"<?php if(isset($_GET['Choose']) && $_GET['Choose']=='generalfeedback') echo ' selected="selected"'; ?>>General Feedback</option>
            <option value="helprequest"<?php if(isset($_GET['Choose']) && $_GET['Choose']=='helprequest') echo ' selected="selected"'; ?>>Help Request</option>
        </select>
        <input type="submit" name="submit" value="Submit" />
    </form>

</body>
</html>

要重定向页面,请阅读文档here;