I have a form built with Chronoforms v5 on Joomla that I need to check an external CRM (http://wiki.x2crm.com/wiki/REST_API_Reference) if the email is already in the database the form will update that record, if that email is not in the database on the CRM it will create a new record. The CRM accepts CURL and right now I have it successfully create new records but ever form that is submitted creates a new record and does not check if it already exists. Attached is the code snippet the CRM guys sent me but I have no idea how to implement it into chronoforms.
// auth settings$url = 'domain name goes here/;$options = ['auth' => ['user' => ‘ADD USER NAME','pass' => ‘ADD PASSWORD',],'headers' => ['Content-Type: application/json'],'data' => null];// get the submitted email$email = urlencode($_POST['email']);// look it up on X2$json = get(“{$url}/Contacts/by:email={$email}.json?_useFirst=1”, $options);$response = json_decode($json, true);if ($response && !empty($response['id'])) {// email found// first set the data you want to change$options[‘data’] = [‘some_key’ => ‘some_value'];// update the existing recordpatch("{$url}/Contacts/{$id}.json”, $options);}else {// email NOT found// do what you’ve always done}// get functionpublic function get($url, $options=array()) {return curlRequest(‘GET’, $url, $options));}// patch functionpublic function patch($url, $options=array()) {return curlRequest(‘PATCH’, $url, $options));}// generic curl functionpublic function curlRequest($method, $url, $options=array()) {$h = curl_init();curl_setopt($h, CURLOPT_URL, $url);curl_setopt($h, CURLOPT_CUSTOMREQUEST, $method);curl_setopt($h, CURLOPT_RETURNTRANSFER, true);curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($h, CURLOPT_SSL_VERIFYHOST, false);// dataif (isset($options['data'])) {curl_setopt($h, CURLOPT_POSTFIELDS, $options['data']);}// headersif (isset($options['headers'])) {curl_setopt($h, CURLOPT_HEADER, array());curl_setopt($h, CURLOPT_HTTPHEADER, $options['headers']);}// authif (isset($options['auth'])) {curl_setopt($h, CURLOPT_USERPWD, "{$options['auth']['user']}:{$options['auth']['pass']}");}// execute$response = curl_exec($h);$error = curl_error($h);$httpcode = curl_getinfo($h, CURLINFO_HTTP_CODE);}I have the current form I can upload upon request.