B
B
barder2020-07-16 11:45:09
1C-Bitrix
barder, 2020-07-16 11:45:09

How to insert an infoblock element into the property of another element — another infoblock?

I have an infoblock with product elements, I created another infoblock for storing reviews, I am passing the parameters for creating, but I can’t understand and find how to transfer a catalog element to the property of another element of another infoblock.
I do the code in the element template:

<div class="content">
  <h3>Отзывы об "<? echo $arResult['NAME'] ?>"</h3>
  <hr>
<? 
$countOnPage = 3;

    $fastUrlsList = array();
    $arSelect = Array("ID", "NAME", "PREVIEW_TEXT", "PROPERTY_SPRAV", "DATE_CREATE");
  $arFilter = Array("IBLOCK_ID"=>34, "ACTIVE"=>"Y", "PROPERTY_SPRAV"=>$arResult["ID"]);
  $res = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, array("nPageSize" => $countOnPage), $arSelect);

        $arFields = $ob->GetFields();
        $fastUrlsList[] = array(
            "NAME" => $arFields["NAME"],
            "PREVIEW_TEXT" => $arFields["PREVIEW_TEXT"],
            "DATE_CREATE" => $arFields["DATE_CREATE"],
        );
       ?>

<div class="row">
  <div class="col-3 ">
    <h5><strong><? print_r($arFields["NAME"]); ?></strong><BR><small><span class="news-date-time"><?echo $arFields["DATE_CREATE"]; ?><BR><? //echo FormatDate("Q", $arFields["DATE_CREATE"]);?></span></small></h5>

  </div>
  <div class="col-auto justify-content-left">
    <? print_r($arFields["PREVIEW_TEXT"]);?>
  </div>
</div> 
<hr>
<?
    }
$arResult["NAVIGATION"] = $res->GetPageNavString("Страницы");
echo $arResult["NAVIGATION"];
?>
</div>

<h3><b><span style="color: #045f20; font-family: Times New Roman, Times;">Добавьте свой отзыв об этой организации</span></b></h3>
<form action="" method="post" enctype="multipart/form-data" class="form-rew">
 <input type="text" placeholder="Введите ваше имя" name="NAME" class="text"> <input type="text" placeholder="Введите ваш электронный адрес" name="EMAIL" class="text"><br>
 <br>
 <input type="text" placeholder="Введите ваш телефон" name="PHONE" class="text"> <textarea placeholder="Введите ваш отзыв" name="REVIEWS" class="text-mess"></textarea><br>
 <input type="submit" class="submit" value="Отправить" name="OK">
</form>
<?

if($_POST["OK"]){
  if(CModule::IncludeModule("iblock")){	
    if($_POST["NAME"]!="" && $_POST["EMAIL"]!="" && $_POST["REVIEWS"]!=""){
      echo "Спасибо, Ваше сообщение отправлено! В ближайшее время его проверят";
      $el = new CIBlockElement;
      $arLoadProductArray = Array(
        "MODIFIED_BY"    	=> $USER->GetID(), // элемент изменен текущим пользователем
        "IBLOCK_SECTION_ID" => false,          // элемент лежит в корне раздела
        "IBLOCK_ID"      	=> 34, // id инфоблока, который вы создали
        "NAME"           	=> $_POST["NAME"], // имя пользователя будет именем элемента
        "ACTIVE"         	=> "N",            // убираем активность
        "PREVIEW_TEXT"   	=> $_POST["REVIEWS"], // отзыв клиента
        "SPRAV"			=> $arResult["ID"], // отзыв клиента
        "DETAIL_TEXT"    	=> "E-Mail: " . $_POST["EMAIL"] . "\nТелефон: " . $_POST["PHONE"], // контактные данные клиента
        "PREVIEW_PICTURE" => CFile::MakeFileArray($fileID)
        );
      if($PRODUCT_ID = $el->Add($arLoadProductArray))
        echo "";
      else
        echo "";   
    }else{
      echo "Заполнены не все поля";
    }
  }
}
?>


I need to pass the current $arResult["ID"] element to the "SPRAV" property, which has a binding to elements

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-07-16
@barder

written in black and white on the docks

arFields
An array of the form Array("field"=>"value", ...) containing the values ​​of the fields of the infoblock element and additionally may contain the field "PROPERTY_VALUES" - an array with all element property values ​​in the form of an array Array("property code"=> "property value"). Where "property code" is a numeric or character code of the property, "property value" is a single value, or an array of values ​​if the property is multiple

You create a new element $el->Add($arLoadProductArray)
In $arLoadProductArray you have written
$arLoadProductArray = Array(
//........................
        "SPRAV" => $arResult["ID"], // отзыв клиента
//........................

And you need
1. If the property is NOT multiple
$arLoadProductArray = Array(
//........................
        "PROPERTY_VALUES" => array(
      "SPRAV" => $arResult["ID"]
    ),
//........................

2. If the property is multiple
$arLoadProductArray = Array(
//........................
        "PROPERTY_VALUES" => array(
      "SPRAV" => array($arResult["ID"])
    ),
//........................

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question