Skip to content

Instantly share code, notes, and snippets.

@anthonysomerset
Created March 29, 2012 13:09
Show Gist options
  • Save anthonysomerset/2237326 to your computer and use it in GitHub Desktop.
Save anthonysomerset/2237326 to your computer and use it in GitHub Desktop.
WP function for gravity forms to allow the submission of a gravityform to sirportly via the remote forms feature
<?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"];
/*
$post_data['name'] = "Test Ticket";
$post_data['email'] = "[email protected]";
$post_data['subject'] = "test subject";
$post_data['message'] = "test message with spaces";
*/
//echo $ticket;
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);
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);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment