Hi,
I installed the latest beta build of Gravity forms and I am trying to get the gform_after_submission hook working with hubspot's API.
This is what I have in my functions.php. Am I using this hook correctly?
add_action("gform_after_submission", "after_submission", 10, 2);
function post_submission_to_api($entry){
$strPost = "";
//create string with form POST data
$strPost = "FirstName=" . urlencode($_POST['input_1'])
. "&LastName=" . urlencode($_POST['input_2'])
. "&Email=" . urlencode($_POST['input_3'])
. "&Phone=" . urlencode($_POST['input_6'])
//. "&Fax=" . urlencode($_POST['fax_number'])
//. "&Website=" . urlencode($_POST['website'])
. "&Company=" . urlencode($_POST['input_4'])
. "&JobTitle=" . urlencode($_POST['input_5'])
//. "&Address=" . urlencode($_POST['address'])
//. "&City=" . urlencode($_POST['city'])
//. "&State=" . urlencode($_POST['state'])
//. "&ZipCode=" . urlencode($_POST['zip_code'])
//. "&Country=" . urlencode($_POST['country'])
. "&Message=" . urlencode($_POST['input_11'])
//. "&NumberEmployees=" . urlencode($_POST['num_employees'])
//. "&AnnualRevenue=" . urlencode($_POST['annual_revenue'])
//. "&CloseDate=" . urlencode($_POST['close_date'])
. "&IPAddress=" . urlencode($_SERVER['REMOTE_ADDR'])
. "&UserToken=" . urlencode($_COOKIE['hubspotutk']);
//set POST URL
$url = "http://applicoinc.app11.hubspot.com/?app=leaddirector&FormName=Final+Contact+Form";
//intialize cURL and send POST data
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost);
@curl_setopt($ch, CURLOPT_URL, $url);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_exec($ch);
@curl_close($ch);
}
This is the PHP code sample provided by hubspot
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
/*******************************
your existing form processing
********************************/
//START HubSpot Lead Submission
$strPost = "";
//create string with form POST data
$strPost = "FirstName=" . urlencode($_POST['first_name'])
. "&LastName=" . urlencode($_POST['last_name'])
. "&Email=" . urlencode($_POST['email'])
. "&TwitterHandle=" . urlencode($_POST['twitter_handle’])
. "&Phone=" . urlencode($_POST['phone_number'])
. "&Fax=" . urlencode($_POST['fax_number'])
. "&Website=" . urlencode($_POST['website'])
. "&Company=" . urlencode($_POST['company'])
. "&JobTitle=" . urlencode($_POST['job_title'])
. "&Address=" . urlencode($_POST['address'])
. "&City=" . urlencode($_POST['city'])
. "&State=" . urlencode($_POST['state'])
. "&ZipCode=" . urlencode($_POST['zip_code'])
. "&Country=" . urlencode($_POST['country'])
. "&Message=" . urlencode($_POST['message'])
. "&NumberEmployees=" . urlencode($_POST['num_employees'])
. "&AnnualRevenue=" . urlencode($_POST['annual_revenue'])
. "&CloseDate=" . urlencode($_POST['close_date'])
. "&IPAddress=" . urlencode($_SERVER['REMOTE_ADDR'])
. "&UserToken=" . urlencode($_COOKIE['hubspotutk']);
//set POST URL
$url = "http://yoursite.hubspot.com/?app=leaddirector&FormName=demorequest";
//intialize cURL and send POST data
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost);
@curl_setopt($ch, CURLOPT_URL, $url);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_exec($ch);
@curl_close($ch);
//END HubSpot Lead Submission
}
?>