Forked from mrbarletta/gravity_forms_webhook_example_suitecrm.php
Created
March 21, 2021 04:08
-
-
Save elaoshi/7a7bdb04ab7dc8f09ac114f10a11c295 to your computer and use it in GitHub Desktop.
Gravity Forms Webhook example - Posting data to SuiteCRM/SugarCRM/LionixCRM - working example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add the following code to your theme functions.php (not recommended as might get lost on updates) or create a plugin | |
//LX - CRM | |
add_action( 'gform_after_submission', 'post_to_crm', 10, 2 ); | |
function post_to_crm( $entry, $form ) { | |
$post_url = 'https://youInstance.lionix.com/index.php?entryPoint=WebToPersonCapture'; | |
$post=false; | |
//Gravity forms has IDs for each of the fields . Some fields, like 1.3, means FIELD 1, subfield 3. Which usually means first_name | |
if($form['title']=="Name of the form"){ | |
$post=true; | |
$body = array( | |
'campaign_id' => '321', | |
'assigned_user_id' => 'bot', //this is the ID of the user you want to be assigned to the contact | |
'moduleDir' => 'Contacts', | |
'first_name' => rgar( $entry, '1' ), | |
'last_name' => rgar( $entry, '2' ), | |
'email1' => rgar( $entry, '4' ), | |
'phone_mobile' => rgar( $entry, '3' ), | |
); | |
}elseif ($form['title']=="Name of the Other form") { | |
$post=true; | |
$body = array( | |
'campaign_id' => '123', | |
'assigned_user_id' => 'bot', | |
'moduleDir' => 'Contacts', | |
'first_name' => rgar( $entry, '1.3' ), | |
'last_name' => rgar( $entry, '1.6' ), | |
'email1' => rgar( $entry, '3' ), | |
'phone_mobile' => rgar( $entry, '2' ), | |
'description' => rgar( $entry, '5' ), | |
); | |
} | |
if($post){ | |
//This is a logging feature you may comment on production - Its here to help you debug the information that is receiving. | |
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/lx.log", PHP_EOL. date_format(date_create(),"Y-m-d H:i:s ") .__FILE__ .":". __LINE__." -- ".print_r($entry, 1).PHP_EOL, FILE_APPEND); | |
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/lx.log", PHP_EOL. date_format(date_create(),"Y-m-d H:i:s ") .__FILE__ .":". __LINE__." -- ".print_r($form['title'], 1).PHP_EOL, FILE_APPEND); | |
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/lx.log", PHP_EOL. date_format(date_create(),"Y-m-d H:i:s ") .__FILE__ .":". __LINE__." -- ".print_r($body, 1).PHP_EOL, FILE_APPEND); | |
GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) ); | |
$request = new WP_Http(); | |
$response = $request->post( $post_url, array( 'body' => $body ) ); | |
GFCommon::log_debug( 'gform_after_submission: response => ' . print_r( $response, true ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment