Gravity Forms hook to run curl script

I am trying to use the after_submission hook for gravity forms to run a curl script that publishes to an API.

There is an entry field that captures the site_name that needs to be published after the user submits the form. The form also passes payment information to Stripe, which is currently working. I tried adding the following code to function.php, but the site is not being published.

 add_action( 'gform_after_submission_5', ‘publish_site’, 10, 2 );

    function publish_site($entry, $form) 

    {

    $site_name = $entry[“11”];

    $ch = curl_init();

    //Set cURL parameters
    curl_setopt($ch, CURLOPT_URL, 'https://api.site.com/api/sites/publish/{$site_name}?test=true');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, 'APIusername:APIpassword');
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',       
        'Content-Length: ' . strlen($data))                                                                       
    );   

    //Perform cURL call and set $output as returned data, if any is returned
    $output = curl_exec($ch);
    curl_close($ch);
}

Related posts

Leave a Reply