将 php 表单发送到 2 个位置
将信息从表单发送到两个不同位置的最佳/最简单方法是什么,基本上在一个表单上有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在服务器端使用 post.php 中的 cURL 来完成此操作。
因此,您已经设置了变量,并且已经对它们进行了验证和清理,然后:
可能需要进行一些更改才能完全按照您的要求进行操作,并且可能需要像浏览器一样伪造标头,但那就是它的基本功能。可能还需要将 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:
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.
不允许跨域发送 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
您的主要问题是 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.