We recently moved our support system from Zendesk to Sirportly as its a cheaper and much cleaner and simpler solution. what i’ve been trying to do for sometime now is to be able to have a form on our site for general contact queries (as well as an old fashioned email address) that would log a ticket in a seperate channel on the support system, the zendesk implementations didnt seem to allow this, with Sirportly however they had basic remote forms which generate a html form that you can embed on a site which is great, just what we wanted.
If you read around you will know that embedding a simple html form on a wordpress site can be challenging in the least at times, so i wanted to avoid that, i already had gravity forms installed from some old historic (no longer used) forms so thought i might be able to hook into that and i found out we could. using the gform_post_submission hook we are able to do just that! so i set about creating a function that hooked in and took the gravity forms data and submitted it to sirportly and came up with a basic “dirty” function, i’m calling it dirty because i’m sure theres a better way to do things most likely via there API and with a gravity forms addon and it also creates an entry on your site too (free backup?), it also doesnt detect errors on the sirportly side (eg with the post), before i get to the code, a little bit of setup is required:
On the Sirportly side, you need to create a remote form as per the docs here: http://www.sirportly.com/docs/admin/ticket-submission/remote-forms you have to fill in the success and failure redirection but we wont use this: i just put in the website home page to allow it to go through, i also deselected include custom fields (but with some manual work this could be made to work also as its only extra fields) then click on test/view form markup to see the html, the most important piece of info you need from here is the form post url, it will be in a format similar to: https://yoursite.sirportly.com/remote_form/formnumber where formnumber is the actual remote form id, keep this for later!
Next import the following form to gravity forms, its just a basic contact form: but helps speed up matters – remember to disable all notifications on the form (you dont want 2 lots of emails now do you!), save the form and take note of its form_id , you’ll need this now.
all thats left to do is link together with some custom code that does the magic, add the following to your functions.php file in your theme (or custom_functions.php within the custom folder if you use thesis) – you may not need the php opening and closing tags – this is just for the benefit of the syntax highlighter
[php]<?php
//edit this to match the form id matching the form you want to post to sirportly for me it was form_id 3
add_action(“gform_post_submission_3”, “post_to_sirportly”, 10, 2);
function post_to_sirportly($entry, $form){
//numbers in here should match the field ID’s in your gravity form
$post_data[‘name’] = $entry[“1”];
$post_data[’email’] = $entry[“2”];
$post_data[‘subject’] = $entry[“3”];
$post_data[‘message’]= $entry[“4”];
foreach ( $post_data as $key => $value) {
$post_items[] = ‘ticket[‘ . $key . ‘]’ . ‘=’ . $value;
}
$post_string = implode (‘&’, $post_items);
//edit this to the post url in the generated HTML for your sirportly remote form
//create cURL connection
$curl_connection = curl_init(‘https://yoursite.sirportly.com/remote_form/formnumber’);
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)”);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
//we dont want sirportly to redirect us as we are allowing gravity forms to handle things
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 0);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
}
?>[/php]
now on line 4 above, edit the action so that it only targets the form you created earlier, in my case it was form_id 3 hence the value, then take the POST url you grabbed from the Sirportly remote form html earlier and replace the url in the curl_init statement with it, save the file and upload it and test your form, if all worked you should be able to successfully submit the form and it will post it off to sirportly and you will get a nice email in your inbox saying a ticket has arrived!
now our contact page has a great form and we get it all logged through sirportly so that we don’t lost track of queries that come in via the website.
Hello,
thanks for your great tutorial. We tried to integrate your code in our website, but something didn´t work.
here is our code: (For security reasons I have deleted our sirportly custom url in this code)
//****************************************
// Sirportly Gravity-Forms Integration
//****************************************
//edit this to match the form id matching the form you want to post to sirportly for me it was form_id 3
add_action(“gform_post_submission_5”, “post_to_sirportly”, 10, 2);
function post_to_sirportly($entry, $form){
//numbers in here should match the field ID’s in your gravity form
$post_data[‘department’] = $entry[“5”];
$post_data[‘name’] = $entry[“1”];
$post_data[’email’] = $entry[“2”];
$post_data[‘subject’] = $entry[“3”];
$post_data[‘message’]= $entry[“4”];
foreach ( $post_data as $key => $value) {
$post_items[] = ‘ticket[‘ . $key . ‘]’ . ‘=’ . urlencode($value);
}
$post_string = implode (‘&’, $post_items);
//edit this to the post url in the generated HTML for your sirportly remote form
//create cURL connection
$curl_connection = curl_init(‘https://[our-sirportly-url]/remote_form/63’);
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)”);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
//we dont want sirportly to redirect us as we are allowing gravity forms to handle things
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 0);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
}
Have you any sugestions, what we could have made wrong?
Greetings,
Markus
I can’t see any obvious errors to the script, my only suggestion is checking the quotes are all correct and that gravity forms field ID’s are all correct