简体   繁体   English

一种具有多个提交动作的表单

[英]One form with multiple submit actions

I have an HTML with three links and a form, and three PHP scripts: send1.php, send2.php, send3.php. 我有一个包含三个链接和一个表单的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> 

First the user clicks on one of the three links to show and fill the form. 首先,用户单击三个链接之一以显示并填写表单。 When he clicks on "send" button, I want that the html form call the right action, according to the clicked link. 当他单击“发送”按钮时,我希望html表单根据单击的链接调用正确的操作。 If the user clicks on "2-Send form two", send2.php must be executed, If he clicks on "3-Send form three", then send3.php must be executed. 如果用户单击“ 2-发送表单二”,则必须执行send2.php;如果用户单击“ 3-发送表单二”,则必须执行send3.php。 I don't want to write a form for each link, how to achieve this please? 我不想为每个链接写一个表格,请问如何实现?

It's hard to say without knowing what you're trying to do. 不知道您要做什么,很难说。

The easiest way would be to add another parameter to your form, and have the form submit to 1 php page which calls one of the other 3 pages depending on the value of that parameter. 最简单的方法是在表单中添加另一个参数,然后将表单提交到1个php页面,该页面根据该参数的值调用其他3个页面之一。

You can either add some radio buttons to your form, or add a hidden input and change the value with javascript whenever the user clicks one of the 3 links. 您可以在表单中添加一些单选按钮,也可以添加隐藏的输入,并在用户单击3个链接之一时使用javascript更改值。

Perhaps you could submit 3 times using AJAX ? 也许您可以使用AJAX提交3次? Here is a simple tutorial using jQuery sending 1 form: http://vimeo.com/1392589 . 这是使用jQuery发送1个表单的简单教程: http : //vimeo.com/1392589

Do it 3 times : 做3次:

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

You can use Javascript for checking which link was clicked 您可以使用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