无需离开网页/网站提交的外在形式 [英] Submit external form without leaving the page/site

查看:145
本文介绍了无需离开网页/网站提交的外在形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了看,通过该网站寻找答案,以这一点,但到我需要什么什么的点(这是密切的,但它实际上并没有提交表单:<一href="http://stackoverflow.com/questions/1263852/$p$pvent-form-redirect-or-refresh-on-submit">$p$pvent形式重定向或刷新提交?)。

I looked through the site for answers to this, but nothing's spot on to what I need (this is close, except it doesn't actually submit the form: Prevent form redirect OR refresh on submit?).

我试图将邮件列表的注册(从托管的混响国度一个注册页面借code)在一个网站。

I'm trying to incorporate a mailing list sign-up (code borrowed from a sign-up page hosted on ReverbNation) to a website.

的形式正确提交,但签署人被重定向到混响国度的网站令人发指呈现的页面。我不能修改自己的脚本,不觉得有一个API,我可以用它来保持整洁。

The form submits properly, but the signee is redirected to a hideously rendered page on ReverbNation's site. I cannot modify their script and don't think there's an API I can use to keep things tidy.

有没有一种方法可以让我在后台提交表单,无需用户重定向?

Is there a way I can submit the form in the background, without the user being redirected?

推荐答案

下面是PHP中的隧道POST的一个例子。

Here's an example in PHP for tunneling a 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;

这篇关于无需离开网页/网站提交的外在形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆