Where is the mistake? I want to make a handler for several contact forms. Login and password changed for security reasons.

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Страница благодарности</title> <link href="css/style.css" type="text/css" rel="stylesheet"/> </head> <body> <? define('CRM_HOST', 'mysite.bitrix24.ru'); // Домен срм системы define('CRM_PORT', '443'); define('CRM_PATH', '/crm/configs/import/lead.php'); define('CRM_LOGIN', 'mywebsite.ru'); // логин define('CRM_PASSWORD', 'eedasd841df'); // пароль /********************************************************************************************/ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_SERVER['POST']['kuh_zvon'])) { 'UF_CRM_1547856855' => $_POST['username2'], // сохраняем имя 'UF_CRM_1485552555' =>$_POST['phone2'], // сохраняем телефон }elseif(isset($_SERVER['POST']['kuh_vopr'])){ 'UF_CRM_1553359931' => $_POST['username3'], // сохраняем имя 'UF_CRM_1574155852' =>$_POST['phone3'], // сохраняем телефон 'UF_CRM_1545224155' =>$_POST['text3'], // сохраняем телефон } }; // авторизация, проверка логина и пароля if (defined('CRM_AUTH')) { $postData['AUTH'] = CRM_AUTH; } else { $postData['LOGIN'] = CRM_LOGIN; $postData['PASSWORD'] = CRM_PASSWORD; } $fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30); if ($fp) { // формируем и шифруем строку с данными из формы $strPostData = ''; foreach ($postData as $key => $value) $strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value); $str = "POST ".CRM_PATH." HTTP/1.0\r\n"; $str .= "Host: ".CRM_HOST."\r\n"; $str .= "Content-Type: application/x-www-form-urlencoded\r\n"; $str .= "Content-Length: ".strlen($strPostData)."\r\n"; $str .= "Connection: close\r\n\r\n"; $str .= $strPostData; // отправляем запрос в срм систему fwrite($fp, $str ); $result = ''; while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); $response = explode("\r\n\r\n", $result); $output = '<pre>'.print_r($response[1], 1).'</pre>'; } else { echo 'Connection Failed! '.$errstr.' ('.$errno.')'; } } //else // { // $output = 'Ошибка'; // } ?> <!-- То, что будет показываться на странице благодарности --> <div id="thanks"><h1>Спасибо, Ваша заявка принята.</h1><p class="Pthanks">Наш менеджер свяжется с Вами в течение 15 минут</p> <p>Если ваша заявка поступила после 17:00, мы обязательно свяжемся с Вами<br/> на следующий день после 9:00.</p><a href="index.html">Вернуться на сайт</a></div>'; </body> </html> 
  • So what error do you get in the end? - Kirill
  • Hello, Kirillu Gives Error HTTP ERROR 500 - Bartdes Design Studio
  • 'UF_CRM_1547856855' => $_POST['username2'], and other similar lines, what do they mean? Perhaps you wanted to thrust it in an associative array? And it turns out, you assign some values ​​to strings. - froxxendsg 7:05 pm
  • is the id of the custom field and assigning it a name - Bartdes Design Studio
  • I did it on the basis of this article and everything works for only one form - Bartdes Design Studio

1 answer 1

Try this:

 if ($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_SERVER['POST']['kuh_zvon'])) { $postData = array( 'TITLE' => $_POST['kuh_zvon'], 'UF_CRM_1547856855' => $_POST['username2'], // сохраняем имя 'UF_CRM_1485552555' => $_POST['phone2'], // сохраняем телефон ); } elseif(isset($_SERVER['POST']['kuh_vopr'])) { $postData = array( 'TITLE' => $_POST['kuh_vopr'], 'UF_CRM_1553359931' => $_POST['username3'], // сохраняем имя 'UF_CRM_1574155852' => $_POST['phone3'], // сохраняем телефон 'UF_CRM_1545224155' => $_POST['text3'], // сохраняем телефон ); } } 
  • does not work, but it works in this form only for one form <code> if ($ _SERVER ['REQUEST_METHOD'] == 'POST') {// get data from the fields and set the name of the lead $ postData = array ('TITLE' => $ _POST ['kuh_zvon'], // save our tag and form the title of the lead 'UF_CRM_1553359931' => $ _POST ['username2'], // save the name 'UF_CRM_1553455522' => $ _ POST ['phone2'], / / save the phone); </ code> - Bartdes Design Studio
  • Updated the answer, so does not work either? - froxxendsg 7:44 pm
  • does not work (((( - Bartdes Design Studio 7:57 pm
  • Remove the line again }; , this bracket is obviously superfluous, maybe it gives an error. - froxxendsg
  • if you remove the syntax error appears - Bartdes Design Studio