
-
AuthorPosts
-
December 19, 2014 at 12:04 am #370320
Hi,
On other sites I have managed to integrate the register_user form with a Hubspot form that has the same fields, so submissions can also be passed into Hubspot. First you have to add the tracking code, but that’s simple and its in the footer – the problem for me is targeting the contact form specifically. Is it possible to change ‘user_register’ below to hook into a contact form (data-avia-form-id=”1″) I have on an Enfold theme? In a nutshell, I need to pass the data from the contact form such as ‘firstname’, ‘lastname’, and ’email’ into my function which then sends to Hubspot.
add_action(‘user_register’, ‘convert_to_hubspot’, 10, 1);
function convert_to_hubspot($user_id) {
$site_url = get_site_url();
$hubspotutk = $_COOKIE[‘hubspotutk’]; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER[‘REMOTE_ADDR’]; //IP address too.
$hs_context = array(
‘hutk’ => $hubspotutk,
‘ipAddress’ => $ip_addr,
‘pageUrl’ => ‘http://www.********.co.uk/contact-us’,
‘pageName’ => ‘Contact-us form’
);/* In order for Hubspot to use this data it needs to formatted in a specific way. */
$hs_context_json = json_encode($hs_context);//We create a simple string that is urlencoded with all of our values, including the hs_context
//value. Need to populate these variables with values from the form.
$firstname=$_POST[‘firstname’];
$lastname=$_POST[‘lastname’];
$email=$_POST[’email’];
$lifecyclestage=$_POST[‘lifecyclestage’];
$hs_persona=$_POST[‘hs_persona’];$str_post = “firstname=” . urlencode($firstname)
. “&lastname=” . urlencode($lastname)
. “&email=” . urlencode($email)
. “&lifecyclestage=” . urlencode($lifecyclestage)
. “&hs_persona=” . urlencode($hs_persona)
. “&hs_context=” . urlencode($hs_context_json); //Leave this one be :)/*The endpoint is the URL we are sending this submission to. Default: https://forms.hubspot.com/uploads/form/v2/{Hub ID}/{Form id} */
$endpoint = “https://forms.hubspot.com/uploads/form/v2/******/*************************************”;print_r($str_post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
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.
$info = curl_getinfo($ch);
// print_r($info);
curl_close($ch);
//echo $response;
//print_r($response);
} `I’ve sent you the link to the site also.
Looking forward to your ideas.
Tim
-
This topic was modified 10 years, 6 months ago by
Tim.
December 19, 2014 at 8:22 pm #370736Hey Tim!
This could work:
https://kriesi.at/support/topic/process-form-params-instead-sending-via-e-mail/Alternatively you can use CF7 + CFDB:
http://cfdbplugin.com/?page_id=747Regards,
Josue -
This topic was modified 10 years, 6 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.