Created
March 16, 2020 11:46
-
-
Save gzalinski/f4c2f55b10708794501d4f9210790801 to your computer and use it in GitHub Desktop.
HubSpot CURL for Gravity Form
This file contains hidden or 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
function curl_to_hubspot($entry, $str_post, $form_ID){ | |
$hubspotutk = $_COOKIE['hubspotutk']; | |
$portalID = '******'; //HubSpot USER ID | |
$hs_context = array( | |
'hutk' => $hubspotutk, | |
'ipAddress' => $entry['ip'], | |
'pageURL' => $entry['source_url'], | |
'pageName' => get_the_title( $entry['post_id']) | |
); | |
$hs_context_json = json_encode($hs_context); | |
$str_post .= "&hs_context=" . urlencode($hs_context_json); | |
$endpoint = "https://forms.hubspot.com/uploads/form/v2/$portalID/$form_ID"; | |
$ch = @curl_init(); | |
@curl_setopt($ch, CURLOPT_POST, true); | |
@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post); | |
@curl_setopt($ch, CURLOPT_URL, $endpoint); | |
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); | |
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = @curl_exec($ch); //Log the response from HubSpot as needed. | |
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code | |
@curl_close($ch); | |
} | |
function apply_online_to_hubspot($entry){ | |
$hsformID = '0ee99b3d-747f-4af5-927d-8fb2767267e5'; //from hubspot form url | |
$str_post = 'name=' . urlencode( $entry[1] ) | |
.'&email='.urlencode( $entry[2] ) | |
.'&phone='.urlencode( $entry[3] ) | |
.'&message='.urlencode( $entry[4] ); | |
curl_to_hubspot($entry, $str_post, $hsformID); | |
} | |
add_action('gform_after_submission_2', 'apply_online_to_hubspot'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment