Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/crm-connector.php Secret
Last active Feb 7, 2019

Embed
What would you like to do?
<?php
/**
* Integrate WPForms 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( $fields, $entry, $form_data, $entry_id ) {
$api_url = 'http://example.com';
$body = array(
'secret' => '',
'name' => $fields['1']['value'],
'email' => $fields['2']['value'],
'phone' => $fields['3']['value'],
'url' => $fields['4']['value'],
'referral' => $fields['5']['value'],
'referral_other' => $fields['6']['value'],
'services' => $fields['7']['value'],
'date' => date( 'Y-m-d' ),
'inquiry' => $fields['8']['value'],
'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( 'wpforms_process_complete_5702', 'be_crm_connector', 10, 4 );
@AhmadTy

This comment has been minimized.

Copy link

AhmadTy commented Feb 7, 2019

can i use it for super forms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.