N
N
Nikita Sokolov2019-11-08 12:08:11
1C-Bitrix
Nikita Sokolov, 2019-11-08 12:08:11

How to add an infoblock in Bitrix not from the admin panel?

The idea is to create an element of the "News" infoblock (I made the infoblock myself, not built-in) not from the admin panel, but using a form on the site. I created the infoportal.element.add.form component on the main page, set up the template to make it beautiful, added a custom visual editor. The infoportal.element.add.form template code is practically untouched, just added a bootstrap design and removed the captcha.
5dc52e23b2cd3166024451.png
The problem is that when adding news, it writes an error, saying that the character code is not specified (which should generally be translated from the name itself, in the admin panel it is so and works) and it does not skip. A separate field for writing a symbolic code is not displayed. I tried to find this field in the $arResult["PROPERTY_LIST_FULL"] array - there is no such field, but when the array is printed, it gives:

NAME => S
TAGS => S
DATE_ACTIVE_FROM => S
DATE_ACTIVE_TO => S
IBLOCK_SECTION => L
PREVIEW_TEXT => T
PREVIEW_PICTURE => F
DETAIL_TEXT => T
DETAIL_PICTURE => F
51 => S

In short, this type field does not exist, but it exists ...
How to fix it? How can I make this form work the same as in the admin panel? How to transfer the symbolic code of an infoblock element? How to automatically generate it from the name?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2019-11-08
@wb_by

Add elements to the infoblock via the Bitrix API. Collect all form data (texts, inputs) and send a post with a request, you can use ajax.
You can use php to create code

function rus2translit($string) {
    $converter = array(
        'а' => 'a',   'б' => 'b',   'в' => 'v',
        'г' => 'g',   'д' => 'd',   'е' => 'e',
        'ё' => 'e',   'ж' => 'zh',  'з' => 'z',
        'и' => 'i',   'й' => 'y',   'к' => 'k',
        'л' => 'l',   'м' => 'm',   'н' => 'n',
        'о' => 'o',   'п' => 'p',   'р' => 'r',
        'с' => 's',   'т' => 't',   'у' => 'u',
        'ф' => 'f',   'х' => 'h',   'ц' => 'c',
        'ч' => 'ch',  'ш' => 'sh',  'щ' => 'sch',
        'ь' => '\'',  'ы' => 'y',   'ъ' => '\'',
        'э' => 'e',   'ю' => 'yu',  'я' => 'ya',
        
        'А' => 'A',   'Б' => 'B',   'В' => 'V',
        'Г' => 'G',   'Д' => 'D',   'Е' => 'E',
        'Ё' => 'E',   'Ж' => 'Zh',  'З' => 'Z',
        'И' => 'I',   'Й' => 'Y',   'К' => 'K',
        'Л' => 'L',   'М' => 'M',   'Н' => 'N',
        'О' => 'O',   'П' => 'P',   'Р' => 'R',
        'С' => 'S',   'Т' => 'T',   'У' => 'U',
        'Ф' => 'F',   'Х' => 'H',   'Ц' => 'C',
        'Ч' => 'Ch',  'Ш' => 'Sh',  'Щ' => 'Sch',
        'Ь' => '\'',  'Ы' => 'Y',   'Ъ' => '\'',
        'Э' => 'E',   'Ю' => 'Yu',  'Я' => 'Ya',
    );
    return strtr($string, $converter);
}

Here is api
https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
and here are more examples
https://camouf.ru/blog-note/2449/
You already have a form, just create another file to process the request from the examples above.
Here is ajax
<form id="form_id" method="post">
//инпуты и тексты, субмит
</form>
<script type="text/javascript">
$(function () {
            $('#form_id').submit(function(e){
                e.preventDefault();
                var data = $(this).serialize();
                $. ajax ({
                    url:'/ajax.php',
                    type:'post',
                    data:data,
                    success:function(res){
                        $('#result').html(res);
                    }
                })
            })
        })  
    </script>

Y
Yaroslav Alexandrov, 2019-11-08
@alexyarik

I would advise you to look in the direction of creating a hermitage button in the public part of CIBlock::GetPanelButtons, by analogy as in the boxed Bitrix 24 done in the company news. When without switching to edit mode, the administrative form of the admin panel is opened to add an element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question