id(); if (!empty($id)) return (string) $id; } catch (Exception $e) {} } if (isset($contact_form->id)) return (string) $contact_form->id; if (isset($contact_form->id_)) return (string) $contact_form->id_; } return ''; } /** * Format and prepare the raw data from contact form 7 */ private function get_posted_data($cf7, &$form_id = '', &$form_title = '') { $token = Leadcrm_Options::get_single_value('leadcrm_token'); $cf_reference = Leadcrm_Options::get_single_value('cf_reference'); $form_id = $this->get_form_id($cf7); $form_title = (is_object($cf7) && method_exists($cf7, 'title')) ? $cf7->title() : ''; if (!isset($cf7->posted_data) && class_exists('WPCF7_Submission') && !empty($token)) { // Contact Form 7 version 3.9 removed $cf7->posted_data and now // we have to retrieve it from an API $submission = WPCF7_Submission::get_instance(); $cf7FormData = $submission ? $submission->get_posted_data() : null; if (!is_array($cf7FormData)) return (array)$cf7; $cf7FormData['leadcrm_token'] = $token; $cf7FormData['cf_reference'] = $cf_reference; $cf7FormData['title'] = $form_title; $cf7FormData['form_name'] = $form_title; $cf7FormData['label'] = Leadcrm_Options::get_form_label('cf7', $form_id, $form_title); $cf7FormData['wp_cf_type'] = "contact_form7"; if ($submission) { return $cf7FormData; } return (array)$cf7; } return null; } /** * This is a wpcf7 callback after the lead is submitted. * Calls a non blocking http API request to 365 CRM with lead data. */ public function submit_cf7_to_leadcrm($contact_form) { $form_id = ''; $form_title = ''; $payload = $this->get_posted_data($contact_form, $form_id, $form_title); $leadcrm_api = new Leadcrm_API('cf7', $form_title, $form_id); $webhook_url = Leadcrm_Constants::get_webhook_url('cf7'); $leadcrm_api->submit_lead_to_leadcrm($webhook_url, $payload, Leadcrm_Content_Type::JSON); } }