簡體   English   中英

一種具有多個提交動作的表單

[英]One form with multiple submit actions

我有一個包含三個鏈接和一個表單的HTML,以及三個PHP腳本:send1.php,send2.php,send3.php。

            <a id=""  name="signup1" href="#signup" >1-Send form one</a>
            <a id=""  name="signup2" href="#signup" >2-Send form two</a>
            <a id=""  name="signup3" href="#signup" >3-Send form three</a>

            <div id="signup"> 
                <form action="send_form_x.php">                     
                    <input id="" name="" type="text">
                    <button type="submit">Send</button>
                </form>
            </div> 

首先,用戶單擊三個鏈接之一以顯示並填寫表單。 當他單擊“發送”按鈕時,我希望html表單根據單擊的鏈接調用正確的操作。 如果用戶單擊“ 2-發送表單二”,則必須執行send2.php;如果用戶單擊“ 3-發送表單二”,則必須執行send3.php。 我不想為每個鏈接寫一個表格,請問如何實現?

不知道您要做什么,很難說。

最簡單的方法是在表單中添加另一個參數,然后將表單提交到1個php頁面,該頁面根據該參數的值調用其他3個頁面之一。

您可以在表單中添加一些單選按鈕,也可以添加隱藏的輸入,並在用戶單擊3個鏈接之一時使用javascript更改值。

也許您可以使用AJAX提交3次? 這是使用jQuery發送1個表單的簡單教程: http : //vimeo.com/1392589

做3次:

$("form").on("submit", function() {
  $.ajax(...) // do the ajax call 1
  $.ajax(...) // do the ajax call 2
  $.ajax(...) // do the ajax call 3
})

您可以使用Javascript檢查單擊了哪個鏈接

<a id=""  name="signup1" href="#signup" onclick="testFunction(signup1)>1-Send form one</a>
<a id=""  name="signup2" href="#signup" onclick="testFunction(signup2)>2-Send form two</a>
<a id=""  name="signup3" href="#signup" onclick="testFunction(signup3) >3-Send form three</a>
         <div id="signup"> 
            <form action="send_form_x.php">   
                <input id="clickedLink" type="hidden">
                <input id="" name="" type="text">
                <button type="submit">Send</button>
            </form>
        </div> 

//JavaScript            
function testFunction(signup){
document.getElementById("clickedLink").value = signup;
} 

暫無
暫無

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

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