There is a need to set up sending requests from the site to ModX in Espo. Lead Capture tried, I could not get
if anyone has a solution, please share
if anyone has a solution, please share
<?php
if(file_exists(MODX_BASE_PATH . 'libs/EspoApiClient.php')) {
require_once(MODX_BASE_PATH . 'libs/EspoApiClient.php');
} else {
$modx->log('error', 'Not found need Class');
return true;
}
$name = '';
$phone = '';
$email = '';
$question = '';
$message = '';
$allFormFields = $hook->getValues();
$ip = $modx->getOption('REMOTE_ADDR', $_SERVER, '');
$formName = $modx->getOption('emailSubject', $formit->config, 'form-'.$modx->resource->get('id'));
foreach ($allFormFields as $key => $value) {
if(strpos($key, 'email') !== false) {
$email = $value;
unset($allFormFields[$key]);
}
if(strpos($key, 'name') !== false) {
$name = $value;
unset($allFormFields[$key]);
}
if(strpos($key, 'phone') !== false) {
$phone = str_replace(['(', ')', ' ', '-'], '', $value);
unset($allFormFields[$key]);
}
if(strpos($key, 'question') !== false) {
$question = "".$value.", ";
unset($allFormFields[$key]);
}
if(strpos($key, 'message') !== false) {
$message = "".$value."";
unset($allFormFields[$key]);
}
}
$message = 'Application "'.$formName.'" from the page "'.$modx->resource->get('pagetitle').'", description: '. $question .' '.$message.', IP - ' . $ip;
// $message = "Filled form from page -" . $allFormFields['page_name'] . '. Name of the form - ' . $formName . '. ' . '. IP - ' . $ip . '. ';
unset($allFormFields['page_name'], $allFormFields['page_url'], $allFormFields['pageId']);
$message .= implode('. ', $allFormFields);
$client = new EspoApiClient('https://xxxxxxxxxx.xxx/); // link to your site here
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // specify your API key here
$formData = [
'firstName' => $name,
'phoneNumber' => $phone,
'emailAddress' => $email,
'description' => $message
];
$client->request('POST', 'LeadCapture/' . $apiKey, $formData);
Comment