gpt4 book ai didi

php - 将 php 表单发送到 2 个位置

转载 作者:行者123 更新时间:2023-12-01 06:40:43 26 4
gpt4 key购买 nike

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

最佳答案

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

可能需要进行一些更改才能完全实现您想要的功能,并且可能需要像浏览器一样伪造 header ,但这就是它的基本功能。可能还需要将 CURLOPT_RETURNTRANSFER 设置为 true。

关于php - 将 php 表单发送到 2 个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4598926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com