繁体   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