N
N
newked2021-09-27 10:41:09
1C-Bitrix
newked, 2021-09-27 10:41:09

How to make two identical forms work on one page in Bitrix?

Hi all. Guys, help me out. I must say right away that I am new to Bitrix, and therefore I need your help.
A problem has appeared. I am making an information page that has two identical forms that add information to one information block. Basically, the form consists of an email field and a submit button.
What I've done?!
1. Created an information block
2. Made a template (bitrix:iblock.element.add.form) with the following code:

<form  id="forma_econ" name="iblock_add" action="<?=POST_FORM_ACTION_URI?>" method="post" enctype="multipart/form-data">
    <?=bitrix_sessid_post()?>
    <div class="forma_econ">
      <div class="forma_econ_mail"><input autocomplete="off" placeholder="<?=GetMessage("EMAIL_TEXT_PL")?>" name="PROPERTY[NAME][0]" type="text" value=""></div>
      <div class="forma_econ_submit"><input type="submit" name="iblock_submit" value="<?=GetMessage("IBLOCK_FORM_SUBMIT")?>" /></div>
    </div>
    <input type="hidden" name="FORM_ID" value="<?=$arParams["FORM_ID"]?>">
  </form>

3. Everything seems to be simple, but I inserted this form (a form with AJAX technology) in two places on one page. And when you try to submit the form below, some kind of glitch occurs, AJAX is ignored, no data is sent.
I don't know where to dig, help guys. I hope you help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Novozhilov, 2021-09-28
@kirk_novozhilov

There are three options:
1. Buffer restart.
Copy the template for the second component. Put the following code before the form:

<? if (count($arResult["ERRORS"]) > 0 || !empty($arResult["MESSAGE"])) {
  $APPLICATION->RestartBuffer();
// здесь обработка MESSAGE или ERRORS
  die();
}
?>

id="forma_econ"
replace with
id="forma_econ<?=$arParams["FORM_ID"]?>"
FORM_ID - must be unique for each form on the page
2. Copy the component to its own namespace.
Add one more custom parameter to the component (as I see, you added FORM_ID ) and inside component.php already submit only if the input parameter is correct.
3. Write your component.
Write a component on d7 with controllers.
https://dev.1c-bitrix.ru/learning/course/index.php...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question