如何将数据提交到其他表单?

时间:2018-04-12 10:16:35

标签: javascript php html forms web

我在一个页面上有一个表单,在另一个网站上有另一个表单。如何将第一张表格上填写的数据提交给另一张?

这是我的代码。

<form action="/action_page.php" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  Comments: <input type="text" name="comments"><br>
 
  <button type="submit">Submit</button><br>
  <button type="submit" formaction="http://www.example.com/formresult.asp")>Submit to another Form</button>
</form>

好的,所以我希望我的用户填写一个表单,但可以选择发送到另一个表单。

我需要这个的原因是因为我有不同的HELP DESK支持团队。在我的目录中的许多html页面上安装了许多不同的联系表格,我想从一个表单中选择发送给我的HELP DESK支持团队的任何人。所有的表格是相同的,PHP文件是相同的。 EMAIL地址是每个团队成员唯一不同的地址。

发送到URL的OPTION也很有帮助。我读到它被称为'绝对URL'和'相对URL'作为属性值,但我认为我编码错了,它对我不起作用。 type =“submit”formaction =“http://www.example.com/form.php”)&gt;提交到其他表单

如果我可以通过代码示例获得一些帮助,我将需要执行这两项操作 - 我可以开始测试我的新游戏部落网站。

提前致谢

请告知

2 个答案:

答案 0 :(得分:0)

尝试此操作,您必须在每次单击按钮时更改操作标记的属性。我已将提交类型更改为按钮,并将隐藏的输入类型设置为提交。希望这有助于你继续前进。

<form action="/action_page.php" method="get" id="myForm">

First name:

<input type="text" name="fname">
<br>

Last name:
<input type="text" name="lname">
<br>
Comments:
<input type="text" name="comments">
<br>
<input type="submit" name="sub" id="sub" style="display:none;">
<button type="button" onClick="javascript:document.getElementById('myForm').setAttribute('action','action_page.php'); javascript:document.getElementById('sub').click();">Submit</button>
<br>
<button type="button" onClick="javascript:document.getElementById('myForm').setAttribute('action','http://www.example.com/formresult.asp'); javascript:document.getElementById('sub').click();">Submit to another Form</button>
<br>
</form>

答案 1 :(得分:-1)

我认为您的问题出在

<form action="/action_page.php" method="get">

你应该将它定位到你的php:

 <form action="/http://www.example.com/formresult.asp" method="get">

然后在接收器文件上,您应该键入结果的处理

相关问题