How to pass news title to form in popup?

  • 0
    Good day!
    I have a page with a news component and each news has a button "Fill a form", when you click on the button, a modal window with a form pops up.
    In this form, in the field, I try to transfer the title of the news (so that it is automatically placed in the form field) But this field "Title" is displayed for all news only for the first news, if I place the variable with the title in a block with a popup, then the Title works correctly. < br />
    Tell me how can I transfer the title to the field in the forms for each news item?
    AJAX Anonymous, Sep 5, 2019

  • 1 Answers
  • 0
    1. In template.php inside a loop on elements, below is an example, I think you will understand what to substitute

    <?foreach($arResult['ITEMS'] as $arItem):?>
    $popupId = randString(10, ['abcdefghijklmnop']);


    <a href="javascript:;" class="btn js-offer-request" data-fancybox="" data-src="#individual-tour-form_<?=$popupId;?>">
    <span>Забронировать экскурсию</span>


    2. Add a parameter to the call of the form component, for example, after ON_NAME

    "POPUP_ID" = & gt; $ popupId

    3. In the form component, add the template.php file

    $popupId = isset($arParams['POPUP_ID']) && $arParams['POPUP_ID'] ? '_'.$arParams['POPUP_ID'] : '';
    <div class="form-modal" id="individual-tour-form<?=$popupId;?>">
    Declan Conway

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!