B
B
B0nG2015-07-14 12:44:48
1C-Bitrix
B0nG, 2015-07-14 12:44:48

How to disable redirect after submitting a web form?

Actually the problem is as follows, there is a form created using the "Web Forms" component. The form works, everything is fine, but there is one caveat.

<form name="SIMPLE_FORM_1" action="/about/" method="POST" enctype="multipart/form-data">

As you can see, the action goes to the "/about/" page, but for some reason, after submitting the form, it redirects to the main page with GET ?WEB_FORM_ID=1&RESULT_ID=156&formresult=addok
. So, how can I get rid of this redirect? So that after submitting the form and reloading the page, I stay on the "about" page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
korshunov_pro, 2018-11-29
@korshunov_pro

I also wondered when submitting the form with Ajax, as an option:

\Bitrix\Main\EventManager::getInstance()->addEventHandler(
    'main',
    'OnBeforeLocalRedirect',
    'formBeforeRedirect'
);

function formBeforeRedirect($redirectUrl) {
    parse_str(parse_url($redirectUrl, PHP_URL_QUERY), $query);
    if (!empty($query['WEB_FORM_ID']) && !empty($query['formresult'])) {
        die(json_encode([
            'error' => 0,
            'message' => ''
        ]));
    }
}

O
Oleg Maksimenko, 2015-07-14
@olegprof

Without editing the component - nothing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question