gpt4 book ai didi

php - 无需离开页面/网站即可提交外部表单

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

我在网站上查找了这个问题的答案,但没有找到我需要的东西(这很接近,只是它实际上没有提交表单: Prevent form redirect OR refresh on submit? )。

我正在尝试将邮件列表注册(从 ReverbNation 上托管的注册页面借用的代码)合并到网站中。

表单已正确提交,但签名者被重定向到 ReverbNation 网站上呈现的丑陋页面。我无法修改他们的脚本,并且不认为有 API 可以用来保持事情整洁。

有没有办法可以在后台提交表单,而无需重定向用户?

最佳答案

以下是 PHP 中用于隧道 POST 的示例。

//set POST variables
$url = 'http://domain.com/url-to-post-to';
$fields = array(
// Add the fields you want to pass through
// Remove stripslashes if get_magic_quotes_gpc() returns 0.
'last_name'=>urlencode(stripslashes($_POST['last_name'])),
'first_name'=>urlencode(stripslashes($_POST['first_name'])),
'email'=>urlencode(stripslashes($_POST['email']))
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));

// returns the response as a string instead of printing it
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

echo $result;

关于php - 无需离开页面/网站即可提交外部表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5098945/

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