Tilda and Bitrix integration with webhook

113 Views Asked by At

I have a site on Tilda and Bitrix CRM (box edition). I trying integrate tilda forms with webhooks. There are 8 similar forms (different hidden fields content) and 1 another form. Files with PHP are on the server https://b24.thesite.ru/myphp_1.php etc. It don't work.

This is my code:

 <?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$wood_type = $_POST['wood_type'];
$is_designer = isset($_POST['is_designer']) ? 'true' : 'false';

$queryUrl = 'https://b24.thesite.ru/rest/93/qqqqqq1q1q1q1qqqqq/crm.lead.add.json';

$queryData = array(
    'fields' => array(
        'title' => 'Новая заявка с mysite.ru',
        'name' => $name,
        'phone' => array(array('VALUE' => $phone, 'VALUE_TYPE' => 'WORK')),
        'select' => $select,
        'is_designer' => $is_designer,
    ),
);

$curl = curl_init($queryUrl);

curl_setopt_array($curl, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_URL => $queryUrl,
    CURLOPT_POSTFIELDS => $queryData,
));

$result = curl_exec($curl);
curl_close($curl);

echo "<pre>";
print_r($result);
print_r(json_decode($result, true));
echo "</pre>";

?>

Tilda says me:

[CODE: 500] webhook URL not avaliable. HTTP/2 500 server: nginx date: Tue, 26 Sep 2023 06:44:07 GMT content-type: text/html; charset = UTF-8 content length:0 vary HTTPS

What's wrong with my PHP?

1

There are 1 best solutions below

0
Lajos Arpad On

First, you have

'select' => $select,

without ever initializing $select. You might want to change it to something like

'select' => ($_POST['select'] ?? ''),

maybe enhancing this with some validation as well.

Second, here

$is_designer = isset($_POST['is_designer']) ? 'true' : 'false';

you set true to $is_designer even if you receive false. You might need to review this to find out whether it's correct.

Third, here

$name = $_POST['name'];
$phone = $_POST['phone'];
$wood_type = $_POST['wood_type'];

you do not check for the existence of these parameters inside $_POST, so you might get awkward results if they happen to be unspecified. You might want to change it to

$name = $_POST['name'] ?? '';
$phone = $_POST['phone'] ?? '';
$wood_type = $_POST['wood_type'] ?? '';

Fourth, wood_type is not even used...