簡體   English   中英

兩個以一種形式提交,並根據帖子采取不同的操作

[英]two submit in one form with diffrent actions based on post

形式如下:

 <form method="POST" action="">
      <input type="text" class="field small-field" name="refone" value="<?php echo Check_Param($refone);?>" />
      <input type="submit" class="button" value="search" name="search"/>
      <input type="submit" class="button" name="print" value="print" />
    </form>

現在我有兩個動作,

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['search']))  {

如果搜索按鈕單擊此操作將僅運行

} else{

如果不提交表單,則將執行此操作。

}

現在這是打印操作,它將使用if語句,然后在if上結果

if(isset($_POST['print'])){

在這里,當我從第一次的其他點擊上方的功能運行,如果打印,然后在這里打印結果,將其導出為PDF作為搜索按鈕,它只是搜索並導致但是在打印會打印出來,

}

所以我的問題是,如何將打印設置為首先搜索是否要搜索,然后搜索到if(print)和結果。

如我在這里所做的,但它在這里不起作用:

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['search']) || isset($_POST['print']))  {
/////////////this code runs first

}

if(isset($_POST['print'])){
/////////this runs secound based on resulted rows of first if
}

所以我該如何管理

問候

您必須使用()將它們包裝起來,以便它們分別進行評估。

if ($_SERVER['REQUEST_METHOD'] == 'POST' && (isset($_POST['search']) || isset($_POST['print'])))  {

    if(isset($_POST['print'])){

       //this runs secound based on resulted rows of first if

    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM