【问题标题】:Is it possible to have two actions on a form?一个表单可以有两个动作吗?
【发布时间】:2019-06-03 19:59:48
【问题描述】:

我有一个当前设置为向 Salesforce 发送数据以收集信息的表单。我还希望将相同的信息发送给 Pardot 以进行跟踪。我知道表单通常只支持一个动作,但我想知道是否有办法解决这个问题。

我尝试直接添加代码,但没有成功,并且无法在网上找到任何专门解决此问题的建议

Salesforce 操作部分是:

<div class="vc_row"><form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

我也希望添加此操作

<form action="http://go.cloudmybiz.com/l/547492/2019-06-03/dsmvd" method="post">

【问题讨论】:

  • 表单只能有一个动作。但是您可以使用 javascript 更改操作属性。
  • 您有两种选择:1)将其发送到您的服务器并让您的服务器发送到这两个地方; 2)编写JavaScript,将表单数据从浏览器中发送到每个地方。

标签: javascript php html forms button


【解决方案1】:

如果用js做的话可以提交2次。示例取自here

<form id="search" action="" method="get" onsubmit="javascript: return SubmitForm();">
<.... ret of the form>
</form> 

和js:

function SubmitForm()
{
    showResultDiv();
    document.forms['search'].action='http://www.google.com/search';
    document.forms['search'].target='frame_result1';
    document.forms['search'].submit();

    document.forms['search'].action='http://www.bing.com/search';
    document.forms['search'].target='frame_result2';
    document.forms['search'].submit();
    return false;
}

【讨论】:

    【解决方案2】:

    你可以试试这样的。使用 JavaScript 发送表单。

    <div class="vc_row">
        <form id="form" method="POST" onsubmit="sendData(event)">
          <input type="text" />
          <input type="submit" />
        </form>
      </div>
    
      <script>
        const sendData = e => {
          e.preventDefault();
          const formData = new FormData(document.getElementById("form"));
    
          fetch("https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8", { method: "POST", body: formData});
          fetch("http://go.cloudmybiz.com/l/547492/2019-06-03/dsmvd", { method: "POST", body: formData});
        };
      </script>
    

    【讨论】:

      猜你喜欢
      • 2013-05-21
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      相关资源
      最近更新 更多