将 php 表单发送到 2 个位置

发布于 2024-10-10 05:33:19 字数 1992 浏览 0 评论 0原文

将信息从表单发送到两个不同位置的最佳/最简单方法是什么,基本上在一个表单上有 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..但我想我做错了什么,如果你有任何建议以其他方式做到这一点那就太好了:]谢谢!

What is the best/easiest way to send information from a form to two different locations, basically have 2 actions on one form. I have a few fields that need to be named differently for each action, for example..

<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 look like this.

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

as you can see i tried using ajax.. but i guess i'm doing something wrong, if you have any suggestions to do this any other way that would be great :] Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终难愈 2024-10-17 05:33:19

您可以在服务器端使用 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。

You could do it server side with cURL in post.php.

So, you have your variables set and they've been validated and cleaned, then:

$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);

Might need to be changed a bit to do exactly what you want, and probably would need to forge the headers like it's a browser doing it, but that is the basic functionality of it. Might also need to set CURLOPT_RETURNTRANSFER to true.

梦旅人picnic 2024-10-17 05:33:19

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

示例 Google 搜索可帮助您找到正确的方向: http://www.google.com/search?q=using+curl+to+submit+form+data+php

sending XHR or Ajax requests is not permitted cross domain. You can achieve this using cURL. i would imagine there are quite a few tutorials about submitting forms using PHP and cURL floating around here.

sample google search to get you in the right direction: http://www.google.com/search?q=using+curl+to+submit+form+data+php

煮茶煮酒煮时光 2024-10-17 05:33:19

您的主要问题是 javascript 不能用于访问其他服务器上的文件,就像您尝试做的那样。一种有效的方法是在您的服务器上放置 PHP 文件,该文件只需设置表单并将其发布(通过使用 javascript 的表单 submit()ted)到远程服务器。

Your main problem is that javascript can't be used to access files on other servers like you're trying to do. An approach that would work would be to have PHP files on your server that just set up forms and post them (via forms submit()ted with javascript) to the remote servers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文