Understanding basic PHP is necessary to use the API:

If you are using WordPress and are using Gravity Forms, this is what you’ll want to add to functions.php. Along with the add_action, you’ll want to add the function below.

Note that the gform_after_submission_1 will need to have the number changed (the 1) to whichever form ID  you’re using.

If you are not using Gravity Forms and WordPress,  you can take the contents inside the function below, and use it on the page that is called on submit of your form.

<?php
add_action(“gform_after_submission_1”, “send_to_sprout”, 10, 2);
function send_to_sprout ($entry, $form){
        /* This is where you specify the information that Sprout Studio needs to create the Lead in your account. The $url
        doesn’t need to be changed. You’ll need to edit the $api_key to be your API key within Sprout Studio. You can find
        this in your account by visitng Settings > Communication > Lead Forms */
        $url =  “https://api.sproutstudio.com/lead/new“;
        $api_key = “YOUR_API_KEY_HERE”;
       
        /* This is where you’ll collect the data from your form */
        $first_name = $_POST[‘input_1’];
        $last_name = $_POST[‘input_2’];
        $email = $_POST[‘input_3’];
        $phone = $_POST[‘input_4’];
        $leadsource = $_POST[‘input_18’];
        $event_type = $_POST[‘input_5’];
        $date = $_POST[‘input_6’];
        $remark .= $_POST[‘input_17’];
       
        /* Edit the fields below, but do not edit the labels */
        $lead = array();
        $lead [‘apikey’] = $api_key;
       
        if ($first_name != “”){
            $lead [‘label-first_name’] =‘First Name’;    // For example, do not edit this
            $lead [‘field-first_name’] = $first_name;     // But you can edit this if you need to
        }
        if ($last_name != “”){
            $lead [‘label-last_name’] =‘Last Name’;
            $lead [‘field-last_name’] = $last_name;
        }
        if ($email != “”){
            $lead [‘label-email’] =‘Email’;
            $lead [‘field-email’] = $email;
        }
        if ($phone != “”){
            $lead [‘label-phone’] =‘Phone Number’;
            $lead [‘field-phone’] = $phone;
        }
       
        if ($leadsource != “”){
            $lead [‘label-leadsource’] =‘Source’;        
            $lead [‘field-leadsource’] = $leadsource;
        }
           
        if ($date != 0){
            $lead [‘label-date’] =‘Event Date’;        
            $lead [‘field-date’] = $date;
        }
       
        if ($event_type != “”){
            $lead [‘label-type’] =‘Event Type’;        
            $lead [‘field-type’] = $event_type;
        }
       
        /* Anything added to field-comments will be added to the end of the note that is created when the Lead is made */
        $lead [‘label-comments’] =‘Remarks’;        
        $lead [‘field-comments’] = $remark;
        /* This is just the connection information, and none of this needs to be touched */
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($lead));
        $response_json = curl_exec($ch);
        $response = json_decode($response_json);
        $httpcode2 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
       
        curl_close($ch);
}
?>

Did this answer your question?