chris.carlin
10/4/2019 - 12:39 AM

Colliers CRM


add_action( 'gform_after_submission', 'ColliersCRM', 10, 2 );
function ColliersCRM($entry, $form){
	function str_replace_first($search, $replace, $subject) {
		$pos = strpos($subject, $search);
		if ($pos === 0) {
			return substr_replace($subject, $replace, $pos, strlen($search));
		}
		return $subject;
	}

	$first_name = rgar($entry,'7');
	$last_name = rgar($entry,'8');
	$email = rgar($entry,'2');
	$mobile = str_replace_first("0", "+61", rgar($entry,'3'));
	$postcode = rgar($entry,'4');
	$hear_about_us = rgar($entry,'5');

    /* Send To Colliers CRM */

    $api_key = 'API KEY HERE';
    $client_id = 'CLIENT ID HERE';

    $url = 'https://enquiries.colliers.com.au/enquiry';

    $data = array(
           "ProjectID" => PROJECT ID HERE,
           "EmailAddress" => $email,
           "Mobile" => $mobile,
           "FirstName" => $first_name,
           "LastName" => $last_name,
           "IPV4" => "1.1.1.1",
           "EnquiryOrigin" => "Project Enquiry",
           "HearAboutUs" => $hear_about_us,
           "Postcode" => $postcode
    );
    $data_string = json_encode($data);
      
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(     
        'CLIENT_ID: ' . $client_id,
        'API_KEY: ' . $api_key
    ));
    $result = curl_exec($ch);
    curl_close ($ch);

    // GFCommon::log_debug( 'gform_after_submission_application: response => ' . print_r( $data, true ) );
}