【问题标题】:How to submit data to another form?如何将数据提交到另一个表单?
【发布时间】:2018-09-22 10:54:25
【问题描述】:

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

这是我的代码。

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

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

我需要这个的原因是因为我有不同的帮助台支持团队。代替我目录中许多 html 页面上的许多不同的联系表格,我只想选择从一个表格发送给我的帮助台支持团队的任何人。所有的表格都是一样的,PHP 文件是一样的。 EMAIL 地址是每个团队成员唯一不同的地方。

发送到 URL 的选项也很有帮助。我读到它被称为“绝对 URL”和“相对 URL”作为属性值,但我认为我编码错误,它对我不起作用。 type="submit" formaction="http://www.example.com/form.php")>提交到另一个表单

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

提前致谢

请指教

【问题讨论】:

  • formaction 正是您提交不同操作的方式。也许那个错误的“)”字符导致了问题?当您按下该按钮时,具体会发生什么?失败的具体情况如何?
  • 如果您有不同的支持团队,那么您很可能会聘请开发人员。这在这里既不清楚也太宽泛了。你需要在这里尝试一下。

标签: javascript php html forms web


【解决方案1】:

试试这个,你必须在每次按钮点击时更改动作标签的属性。我已将提交类型更改为按钮并将隐藏的输入类型设置为提交。希望这可以帮助您继续前进。

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

【讨论】:

    【解决方案2】:

    我认为你的问题出在

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

    你应该像这样将它定位到你的php:

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

    然后在接收器文件中键入结果的处理方式

    【讨论】:

    • 这不是解决方案。 OP 希望“提交”提交到 action_page.php 和“提交到另一个表单”提交到 example.com/formresult.asp。您的解决方案仅将一种类型替换为另一种类型。
    猜你喜欢
    • 1970-01-01
    • 2020-05-10
    • 2016-03-21
    • 1970-01-01
    • 2021-11-13
    • 2014-08-29
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多