A
A
Andrey2017-08-29 18:01:09
PHP
Andrey, 2017-08-29 18:01:09

Bitrix: feedback form on AJAX. Why is there no result in the server response?

I'm making a form in a popup window without reloading.

On click, I send a POST request, I catch it in the template:

if($_POST['FEEDBACK_AJAX'] === 'Y') {
    $APPLICATION->RestartBuffer();
    header('Content-type: application/json');
        echo json_encode(array(
            'arResult' => $arResult
        ));
        die(); 
}


As a result, this arResult comes up:
arResult: {
 PARAMS_HASH : "9bacde48eda26d431ef26c0ad582f49d"
capCode: "0d68181348986b338adf6b02cf954da2"
}


If you turn off Ajax and try to just submit the form, then using print_r () the following content of arResult is displayed:
Array
(
    [PARAMS_HASH] => 9bacde48eda26d431ef26c0ad582f49d
    [ERROR_MESSAGE] => Array
        (
            [0] => Вы не написали сообщение.
        )

    [MESSAGE] => 
    [AUTHOR_NAME] => admin
    [AUTHOR_EMAIL] => [email protected]
)


It has ERROR_MESSAGE! And if you send by Ajax - no. Why is that? How to deal with it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2017-08-29
@f-end

Most likely, the component (not the template) does not receive all the necessary parameters that come with a regular post. I'm confused why your captcha pops up. The component is standard - form.result.new?
Try to see the difference in requests between normal and ajax by adding the code:

echo json_encode(array(
            'arResult' => $arResult,
            'GET' => $_GET,
            'POST' => $_POST,
        ));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question