1

将信息从表单发送到两个不同位置的最佳/最简单方法是什么,基本上在一个表单上有 2 个操作。例如,我有一些字段需要为每个操作以不同的方式命名。

<form id="form" name="form" action='post.php' method='POST' accept-charset='UTF-8'><input type='hidden' name='xnQsjsdp' value=SlGqwqH3ITc$/>  <input type='hidden' name='xmIwtLD' value=x4LHs39QfKiFkCs1PrsnsG-*B6-MHnNR/>  <input type='hidden' name='actionType' value=TGVhZHM=/> <input type='hidden' name='returnURL' />
<input name='firstName' type='text' id="firstName" style="float:left; width:45%;" maxlength='40' />
<input name='lastName' type='text' id="lastName" style="float:left; width:45%;" maxlength='40' />
<input type="submit" />
</form>

post.php 看起来像这样。

<?php

    if ($_SERVER['REQUEST_METHOD'] == "POST") {

      $hidden1      = $_POST["xnQsjsdp"];
      $hidden2      = $_POST["xmIwtLD"];
      $hidden3      = $_POST["actionType"];
      $hidden4      = $_POST["returnURL"];
      $firstName    = $_POST["firstName"];
      $lastName     = $_POST["lastName"];
      $street       = $_POST["Street"];
      $city         = $_POST["City"];
      $State        = $_POST["State"];
      $zipCode      = $_POST["Zip"];
      $email        = $_POST["Email"];
      $phone        = $_POST["Phone"];
      $LEADCF7      = $_POST["LEADCF7"];
      $zohoPrams    = "xnQsjsdp=$hidden1&xmIwtLD=$hidden2&actionType=$hidden3&returnURL=$hidden4&First Name=$firstName&Last Name=$lastName";
      $maxPrams     = "FName=$firstName&LName=$lastName";

    };

?>
<script>
$(function() { // setup an onReady (similar to onLoad) handler
        $.post("https://crm.zoho.com/crm/WebToLeadForm", <?php echo $zohoPrams; ?>; // post to first address
        $.post("http://www.max360group.com/", <?php echo $maxPrams; ?>; // post to second address
});
</script>

如您所见,我尝试使用ajax ..但我想我做错了,如果您有任何建议可以以任何其他方式来做这将是很棒的:] 谢谢!

4

3 回答 3

4

您可以在 post.php 中使用 cURL 在服务器端进行操作。

因此,您已经设置了变量,并且它们已经过验证和清理,然后:

$zoho = curl_init("https://crm.zoho.com/crm/WebToLeadForm");
curl_setopt($zoho, CURLOPT_SSL_VERIFYPEER, false); //Note, not very secure.  Would have to get certificate otherwise.  Look up how to.
curl_setopt($zoho, CURLOPT_FOLLOWLOCATION, 1); //Makes sure that it follows any redirects
curl_setopt($zoho, CURLOPT_RETURNTRANSFER, 1); //Returns the result instead of outputting it to the browser
curl_setopt($zoho, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); //Will make the end server think it was submitted with Firefox, and not by a server using cURL.
curl_setopt($zoho, CURLOPT_POST, 1);
curl_setopt($zoho, CURLOPT_POSTFIELDS, $zohoprams);  
//If you want the rest of the $_POST data and not just what you set above in $zohoprams, 
//CURLOPT_POSTFIELDS takes either an array, which will automatically do the appropriate thing with it as a $key=$value, or a string like you have formatted for $zohoprams
curl_exec($zoho);
curl_close($zoho);

$max = curl_init('http://www.max360group.com/');
curl_setopt($max, CURLOPT_POST, 1);
curl_setopt($max, CURLOPT_POSTFIELDS, $maxprams);
curl_setopt($max, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($max, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($max, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_exec($max);
curl_close($max);

可能需要进行一些更改才能完全按照您的意愿进行操作,并且可能需要像浏览器一样伪造标题,但这是它的基本功能。可能还需要将 CURLOPT_RETURNTRANSFER 设置为 true。

于 2011-01-04T22:13:01.987 回答
2

不允许跨域发送 XHR 或 Ajax 请求。您可以使用 cURL 实现此目的。我想这里有很多关于使用 PHP 和 cURL 提交表单的教程。

示例 google 搜索让您朝着正确的方向前进:http ://www.google.com/search?q=using+curl+to+submit+form+data+php

于 2011-01-04T22:10:06.910 回答
0

您的主要问题是 javascript 不能像您尝试的那样用于访问其他服务器上的文件。一种可行的方法是在您的服务器上安装 PHP 文件,这些文件只是设置表单并将它们(通过submit()使用 javascript 的表单)发布到远程服务器。

于 2011-01-04T22:11:03.290 回答