一个表单包含多个提交操作

One form with multiple submit actions

本文关键字:包含多 提交 表单 操作 一个      更新时间:2024-06-19

我有一个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-Send form two",则必须执行send2.php;如果用户点击了"3-Send form three",那么必须执行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;
}