gform_after_submission 发布到第三方 API [英] gform_after_submission Post to Third Party API
问题描述
我正在尝试使用我客户的 WordPress 网站的functions.php 文件中的 gform_after_submission 挂钩将此信息字符串发送到第三方 API(此 url 由第三方客户端提供,我需要匹配它每次注册):https://thirdpartywebsite.com/api_addNewProfile.php?gid=yourGroupID&fn=John&mi=E&ln=Doe&un=john@email.com&p=testpw&g=Male一个>
I am trying to use the gform_after_submission hook in the functions.php file of my client's WordPress website to send this string of information to a third party API (this url was provided by the third-party client and I need to match it with every registration): https://thirdpartywebsite.com/api_addNewProfile.php?gid=yourGroupID&fn=John&mi=E&ln=Doe&un=john@email.com&p=testpw&g=Male
这是我在我的functions.php文件中设置的:
This is what I set up on my functions.php file:
add_action('gform_after_submission', 'post_to_third_party', 10, 2);
function post_to_third_party($entry, $form) {
$post_url = 'https://thirdpartywebsite.com/api_addNewProfile.php';
$body = array(
'gid' => "yourGroupID",
'fn' => $entry['1.3'],
'mi' => "",
'ln' => $entry['1.6'],
'un' => $entry['2'],
'p' => "test",
'g' => $entry['3']
);
$request = new WP_Http();
$response = $request->post($post_url, array('body' => $body));
}
我正在使用 GF 用户注册插件,因此当新会员在我客户的网站上注册时,他们将用户名和密码设置为登录到他们的个人资料页面,并且他们应该能够登录第三方在线应用程序与他们通过注册表设置完全相同的用户名和密码.
I'm using the GF User Registration addon so when a new member registers on my client's website they set their username and password to login to their profile page, and they should be able to login to the third-party online application with the exact same username and password that they set up through the registration form.
供参考:
- fn = 名字
- mi = 中间名首字母(我现在只想为中间名首字母传递一个空格)
- ln = 姓
- un = 用户名
- p = 密码(暂时设置为test")
- g = 性别
当我用相关的用户信息填写完整的 url 时,一切正常,我可以登录到在线应用程序.我一直无法让我的 Gravity Forms 注册表正确发布数组.
When I fill in the full url with the relevant user information everything works without any issues and I can login to the online application. I have been unable to get my Gravity Forms registration form to post the array correctly.
如果你们能指出我正确的道路,我将不胜感激.
If you all could point me down the right path I would greatly appreciate it.
推荐答案
您的代码示例显示您正在使用 POST http 方法而不是 GET 方法.我建议您按照示例中所示构建 URL,然后使用完全构建的 url 执行 WP_Http 请求.或者,您可以尝试 $request->get first 看看是否有效.
Your code sample shows you are using a POST http method instead of a GET method. I'd suggest you build the URL as you show in your example, and just do a WP_Http request with the fully built url. Or, you could try a $request->get first and see if that works.
这篇关于gform_after_submission 发布到第三方 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!