get_fields($form_id); $form_data = json_decode(json_encode($map_data), true); $body = array(); foreach ($form_data as $index => $field) { $key = $field["mf_input_label"]; $raw_value = isset($form_values[$index]) ? $form_values[$index] : null; $value = $this->extract_value_by_type($field, $raw_value); if ($value === null) continue; // Only include if the form data is exist $body[$key] = $value; } return $body; } /** * This is a Metform callback after the lead is submitted. * Calls a non blocking http API request to 365 CRM with lead data. */ public function submit_to_leadcrm($form_id, $form_values, $form_settings, $attributes) { // $form_name = $form_data["settings"]["form_title"]; $form_name = isset($form_settings["form_title"]) ? $form_settings["form_title"] : ''; $leadcrm_api = new Leadcrm_API('metform', $form_name, $form_id); $token = Leadcrm_Options::get_single_value('leadcrm_token'); $cf_reference = Leadcrm_Options::get_single_value('cf_reference'); $endpoint = $leadcrm_api->build_api_endpoint(); $payload = $this->extract_fields($form_id, $form_values); $payload['leadcrm_token'] = $token; $payload['cf_reference'] = $cf_reference; $leadcrm_api->submit_lead_to_leadcrm($endpoint, $payload, Leadcrm_Content_Type::JSON); } }