具有多个提交操作的表单 [英] One form with multiple submit actions
问题描述
我有一个带有三个链接和一个表单的HTML,以及三个PHP脚本:send1.php,send2.php,send3.php。
I have an HTML with three links and a form, and three PHP scripts: 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。
我不想为每个链接写一个表格,请问如何实现这个功能?
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. 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. I don't want to write a form for each link, how to achieve this please?
推荐答案
使用Javascript来检查哪个链接被点击
You can use Javascript for checking which link was clicked
<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;
}
这篇关于具有多个提交操作的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!