Hello! There is such a task to make a web interface for sending SMS. Roughly speaking there is a text field and a field for several numbers. By pressing the button using the POST method, a message is sent in the form: номер:текст , the message ID returned. How do I store in the info block ID:номер within one item?

  • Do you really need to use information blocks? - Mihanik71
  • @ Mihanik71, yes, because I need to store information about sent messages - S.Ivanov
  • 2
    It is better to use for these purposes Highload blocks. But if you really need to use the information block property, then I would create, just in case, the multiple PROPERTY_PHONE property, which would put the phone number in the value, and the resulting ID in the XML_ID . So it is more correct from the point of view of architecture, as it seems to me. - Nikolaj Sarry
  • XML_ID what is XML_ID where to read more about this? - S.Ivanov
  • XML_ID exists on properties of type "list". In principle, by such an analogy, you can create your own key-value type. - Nikolaj Sarry

1 answer 1

If you need to store in the information block, then:

  1. You must create a property "phone number" (PROPERTY_PHONE)
  2. On the page we write a handler that will add the item.

Handler Code:

 <? if(isset($_REQUEST["phone"]) && isset($_REQUEST["mess"]) ){ $el = new CIBlockElement; $PROP = array(); $PROP["PHONE"] = $_REQUEST["phone"]; // свойству с кодом 12 присваиваем значение "Белый" $arLoadProductArray = Array( "MODIFIED_BY" => $USER->GetID(), // элемент изменен текущим пользователем "IBLOCK_SECTION_ID" => false, // элемент лежит в корне раздела "IBLOCK_ID" => 18,//указать свой "PROPERTY_VALUES"=> $PROP, "NAME" => "Элемент", "ACTIVE" => "Y", // активен "DETAIL_TEXT" => $_REQUEST["mess"], ); if($PRODUCT_ID = $el->Add($arLoadProductArray)) echo $PRODUCT_ID; else echo "Error: ".$el->LAST_ERROR; }?> 

But for your task it is better to use “Highload-blocks”.

  • those. It turns out the phone number is in the property, and the ID in the full news? I also need to store several, not one, a pair of ID:номер , for this purpose it seems to me that it does not quite fit - S.Ivanov
  • Well, you can create your own element for each number, or you can make the PHONE property multiple and write down all the options - Mihanik71