Last active
February 6, 2024 14:42
-
-
Save aliboy08/f9ea3afd4962d5354831d0451555c515 to your computer and use it in GitHub Desktop.
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 | |
// Send data to hubspot | |
$hubspot_portal_id = '4421750'; | |
$hubspot_form_guid = '35d60c88-89f4-46a6-b2e8-996f60cd5445'; | |
$url = 'https://forms.hubspot.com/uploads/form/v2/'. $hubspot_portal_id .'/'. $hubspot_form_guid; | |
$data = array(); | |
if( isset($_POST['ff_quiz_first_name']) ) $data['firstname'] = $_POST['ff_quiz_first_name']; | |
if( isset($_POST['ff_quiz_last_name']) ) $data['lastname'] = $_POST['ff_quiz_last_name']; | |
if( isset($_POST['ff_quiz_email']) ) $data['email'] = $_POST['ff_quiz_email']; | |
if( isset($_POST['ff_quiz_business_name']) ) $data['business_name'] = $_POST['ff_quiz_business_name']; | |
if( isset($_POST['ff_quiz_your_role']) ) $data['your_role'] = $_POST['ff_quiz_your_role']; | |
if( isset($_POST['ff_quiz_postcode']) ) $data['zip'] = $_POST['ff_quiz_postcode']; | |
$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REDIRECT_URL]"; | |
$hs_context = array( | |
'hutk' => ( isset($_COOKIE['hubspotutk']) ) ? $_COOKIE['hubspotutk'] : '', // install hubspot tracking code https://knowledge.hubspot.com/articles/kcs_article/reports-settings/install-the-hubspot-tracking-code | |
'ipAddress' => $_SERVER['HTTP_X_REAL_IP'], | |
'pageUrl' => $current_url, | |
'pageName' => get_the_title(), | |
); | |
$data['hs_context'] = json_encode($hs_context); | |
$data_string = http_build_query($data); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/x-www-form-urlencoded', | |
'Content-Length: ' . strlen($data_string) | |
)); | |
$result = curl_exec($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment