簡體   English   中英

使用PHP_SELF第二個按鈕處理表單數據以將表單數據發布到另一個頁面

[英]Process form data using PHP_SELF second button to post form data to another page

我有一個使用以下方法發布數據的表單:“ method =” post“ enctype =” multipart / form-data“>

過帳的數據已執行了一些計算,並將結果反饋到表單字段。 提交按鈕稱為計算。 if(isset($ _ POST ['Calculate']))

這很好。 但是,我添加了另一個名為“打印”的按鈕,我想使用該按鈕將數據發布到另一個頁面上。 if(isset($ _ POST ['Print']))

有沒有一種方法可以做到這一點? 單擊“打印”按鈕時,基本上將表單操作從PHP_SELF更改為newpage.php。

謝謝。

您唯一能夠做到這一點的方法是使用javascript(最有可能是jQuery)來更改單擊按鈕時表單的動作。

如果是我,則將表單操作設置為您想要的打印按鈕。 然后,使用jquery / ajax調用您的腳本(或者如果可以使用javascript完成,請在客戶端進行操作並將其保存到服務器),然后單擊該按鈕進行計算。

使用JQuery發布了一個解決方案:

jQuery / Javascript根據輸入字段更改表單操作

除了使用純Javascript,我可能會做一些非常相似的事情:

<script type="text/javascript">
<!--
function changeformaction(newact)
{
  document.myformname.action=newact;
}
//-->
</script>

然后使用類似這樣的東西:

<form name="myformname" action="Calculate.php" method="POST">

<input type="submit" name="Calculate" onclick="changeformaction('Calculate.php');">
<input type="submit" name="Print" onclick="changeformaction('Print.php');">
</form>

另外,您可以使用如下所示的隱藏字段:

<form name="myformname" action="Calculate.php" method="POST" onsubmit="this.action=document.myformname.hiddenaction.value;">

<input type="submit" name="Calculate" onclick="document.myformname.hiddenaction.value='Calculate.php';">
<input type="submit" name="Print" onclick="document.myformname.hiddenaction.value='Print.php';">
<input type="hidden" name="hiddenaction" value="">
</form>

嘗試兩者之一。

暫無
暫無

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

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