Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Integrate Gravity Forms with CRM
*
* @author Bill Erickson
* @link http://www.billerickson.net/contact-form-integration/
*
* @param array $fields
* @param array $entry
* @param array $form_data
* @param int $entry_id
*/
function be_crm_connector( $entry, $form ) {
$api_url = 'http://example.com';
$body = array(
'secret' => '',
'name' => $entry['1'],
'email' => $entry['2'],
'phone' => $entry['3'],
'url' => $entry['4'],
'referral' => $entry['5'],
'referral_other' => $entry['6'],
'services' => $entry['7'],
'date' => date( 'Y-m-d' ),
'inquiry' => $entry['8'],
'status' => '1',
);
$request = wp_remote_post( $api_url, array( 'body' => $body ) );
// Simple error handling
if ( is_wp_error( $request ) ) {
$msg = "There was an error trying to push a lead to the CRM.\n";
$msg .= 'Error returned: ' . $error = $request->get_error_message() . "\n\n";
$msg .= "The lead below may need to be added to the CRM manually.\n";
$msg .= $body['name'] . ' ' . $body['email'];
wp_mail( get_bloginfo( 'admin_email' ), 'CRM Connector Error', $msg );
}
}
add_action( 'gform_after_submission_1', 'be_crm_connector', 10, 2 );
@fernandarosh

This comment has been minimized.

fernandarosh commented Feb 20, 2017

Hi,
How can I use this with contact form 7?

@nassimBo55

This comment has been minimized.

nassimBo55 commented Mar 15, 2017

Hi Fernando,

for contact form you should use this instead:

https://gist.github.com/billerickson/7778c517031ea99c9eea#file-crm-connector-php

Thanks to @billerickson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment