Created
July 26, 2014 06:49
-
-
Save atwellpub/6ffef4cd082470b5c4b7 to your computer and use it in GitHub Desktop.
Example of how to relay lead data to an service api during a form submission.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('inbound_store_lead_post' , 'relay_data_to_custom_service' ); | |
function relay_data_to_custom_service( $lead_data ) { | |
if ($lead_data['page_id'] != '75' ) { | |
return; | |
} | |
/* Decode json that carries mapped lead data */ | |
$lead_data = json_decode( stripslashes($lead_data['form_input_values']) , true ); | |
/* Open CURL connection to destination URL */ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://www.service.com/api/' ); | |
curl_setopt($ch, CURLOPT_POST, 1 ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS , $lead_data ); | |
/* execute and gret response */ | |
$return = curl_exec($ch); | |
/* If return doesn't contain any response data then throw an errorin the php error log file */ | |
if(!$return) { | |
error_log( 'Action Event - Sending Data to External URL - Error <h2>Settings</h2><pre>'.'Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl).'</pre>' ); | |
} | |
curl_close($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment