简体   繁体   English

如何通过1个表单提交到2个域?

[英]How Can I Post to 2 Domains on 1 Form Submit?

I have a form on my site that submits data to Salesforce, via php POST. 我的网站上有一个表单,可通过php POST将数据提交给Salesforce。 At the same time I'm trying to POST the same data to my own site so I can store the info in my own database. 同时,我试图将相同的数据发布到自己的站点,以便将信息存储在自己的数据库中。 How can I POST to both places with php? 如何使用php发布到两个地方?

Here's the form for reference: 这是供参考的表格:

<form class="gk-form" id="GK-Form" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" novalidate="novalidate">
    <input type="hidden" name="oid" value="000000000000">
    <input id="ReturnUrl" type="hidden" name="retURL" value="https://exampleurl.com">
    <input id="company" type="hidden" name="company" value="examplecompany">
    <input id="lead_source" type="hidden" name="lead_source" value="LeadSource">
    <input class="sidebar-form valid" id="last_name" type="text" name="last_name" placeholder="First Name ..." required="">
    <input class="sidebar-form valid" id="email" type="email" name="email" placeholder="Email address ..." required="">
    <input class="sidebar-form" type="submit" name="lead_submit" value="Try It Free!">
</form>

you could turn it into an AJAX request, by overloading the onSubmit event, then you can run 2 ajax calls to each server capture the output from both, and go from there. 您可以通过重载onSubmit事件将其转换为AJAX请求,然后可以对每个服务器运行2个ajax调用,以捕获两者的输出,然后从那里进行。

Or you can send the POST request to your server first, then your server can cURL the salesforce URL with POST type and the POST data as the fields in your form. 或者,您可以先将POST请求发送到您的服务器,然后您的服务器可以使用POST类型和POST数据作为表单中的字段来卷曲Salesforce URL。

You can do this with jQuery, by making an ajax call. 您可以通过进行ajax调用来使用jQuery。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#GK-Form").submit(function(e)
        {
            var postData = $("#GK-Form").serializeArray();
            var formURL0 = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
            $.ajax(
            {
                url : formURL0,
                type: "POST",
                data : postData,
                success:function(data, textStatus, jqXHR) 
                {
                    alert("post sent to first server");
                },
                error: function(jqXHR, textStatus, errorThrown) 
                {
                    //if fails      
                }
            });
            var formURL1 = "your second url"
            $.ajax(
            {
                url : formURL1,
                type: "POST",
                data : postData,
                success:function(data, textStatus, jqXHR) 
                {
                    alert("post sent to second server");
                },
                error: function(jqXHR, textStatus, errorThrown) 
                {
                    //if fails      
                }
            });


        });
    });

</script>

HTML form: HTML形式:

<form class="gk-form" id="GK-Form">
    <input type="hidden" name="oid" value="000000000000">
    <input id="ReturnUrl" type="hidden" name="retURL" value="https://exampleurl.com">
    <input id="company" type="hidden" name="company" value="examplecompany">
    <input id="lead_source" type="hidden" name="lead_source" value="LeadSource">
    <input class="sidebar-form valid" id="last_name" type="text" name="last_name" placeholder="First Name ..." required="">
    <input class="sidebar-form valid" id="email" type="email" name="email" placeholder="Email address ..." required="">
    <input class="sidebar-form" type="submit" id="submit_Button" name="lead_submit" value="Try It Free!">
</form>

Well, let me propose the following 3 simple steps: 好吧,让我提出以下3个简单步骤:

  1. First, you need to make the form submit to your own script. 首先,您需要使表单提交到您自己的脚本。
  2. Then do want ever you intented with the received data. 然后,无论您希望接收的数据是什么。
  3. Finally, when you're done, you use a HttpRequest object ( http://www.php.net/manual/de/class.httprequest.php ) to generate a request that forwards all of the data to the salesforce server. 最后,完成后,您将使用HttpRequest对象( http://www.php.net/manual/de/class.httprequest.php )生成将所有数据转发到salesforce服务器的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM