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
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));
}
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.
For reference:
- fn = first name
- mi = middle initial (I just want to pass a blank space for middle initials for now)
- ln = last name
- un = username
- p = password (set to "test" for the moment)
- g = gender
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.
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.