PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

gform_after_submission hook with 3rd API (Hubspot)

  1. 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
    }
    ?>
    Posted 12 years ago on Wednesday October 12, 2011 | Permalink
  2. The form in question in here: http://applicoinc.com/contact

    Posted 12 years ago on Wednesday October 12, 2011 | Permalink
  3. Bump...we also have this question. Gravity folks, what file do we put the HubSpot code into?

    Posted 12 years ago on Tuesday November 22, 2011 | Permalink
  4. @sclemens we'll continue this discussion on the other topic you opened. Thank you

    http://www.gravityhelp.com/forums/topic/gform_after_submission-hook-with-3rd-api-hubspot

    Posted 12 years ago on Wednesday November 23, 2011 | Permalink

This topic has been resolved and has been closed to new replies.