使用提交表单调用2(两个)操作

时间:2018-02-24 18:36:10

标签: javascript php html forms submit

想要使此提交按钮触发2个不同的操作。

  1. 搜索 - 使用index.php操作,如图所示。

  2. 使用着陆页(或任何页面)打开新标签页或新窗口。

  3. 重要的是index.php有一个"复杂"为我编码并去那里会更加挑战自己。所以我更喜欢保留第一个功能,并以某种方式在这里添加第二个""。 如何添加第二个动作?

    <form class="destinations-form" action="index.php" method="post">
      <div class="input-line">
        <input name="search" type="text" name="destination" value="" 
         class="form-input check-value" placeholder="Looking for..." />
        <button type="submit" name="destination-submit" 
         class="form-submit btn btn-special">GO</button>
      </div>
    </form>
    

1 个答案:

答案 0 :(得分:0)

你不能在表单中放两个动作,但你可以做的是将index.php改为index.php?p = landingPage

<form class="destinations-form" action="index.php?p=landingPage" method="post">
  <div class="input-line">
    <input name="search" type="text" name="destination" value="" 
     class="form-input check-value" placeholder="Looking for..." />
    <button type="submit" name="destination-submit" 
     class="form-submit btn btn-special">GO</button>
  </div>
</form>

然后在index.php中添加以下内容,它会重定向到您的目标网页。

if (isset($_GET['landingPage'])) {
    $redirect="http://mylandingpage.com";
    header("Location: $redirect");
}