D
D
DeeUs2019-03-25 14:45:36
1C-Bitrix
DeeUs, 2019-03-25 14:45:36

How to make ajax form with saving results in admin panel?

Hello!
What is the best way to implement a form (ajax) so that the results are stored in the admin panel and a notification with the filled data is sent to the administrator's mail (or to a separately registered mail).
on the Internet I came across different implementations both through main: feedback and through iblock.element.add and through bittrix: form.result.new. but since I'm not really into Bitrix yet - I don't quite understand how it's better and more correct.
Thank you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2019-03-25
@DeeUs

You asked a lot of questions in one post.
Here's a great example:

<?
$el = new CIBlockElement;
$PROP = array();
$PROP[12] = "Белый";  // свойству с кодом 12 присваиваем значение "Белый"
$PROP[3] = 38;        // свойству с кодом 3 присваиваем значение 38
$arLoadProductArray = Array(
  "MODIFIED_BY"    => $USER->GetID(), // элемент изменен текущим пользователем
  "IBLOCK_SECTION_ID" => false,          // элемент лежит в корне раздела
  "IBLOCK_ID"      => 18,
  "PROPERTY_VALUES"=> $PROP,
  "NAME"           => "Элемент",
  "ACTIVE"         => "Y",            // активен
  "PREVIEW_TEXT"   => "текст для списка элементов",
  "DETAIL_TEXT"    => "текст для детального просмотра",
  "DETAIL_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/image.gif")
  );
if($PRODUCT_ID = $el->Add($arLoadProductArray))
  echo "New ID: ".$PRODUCT_ID;
else
  echo "Error: ".$el->LAST_ERROR;
?>

Create an infoblock with properties.
Create a page, in it a form with fields, when submitting the form, make a post-request to the page with the code above.
Here is an example for ajax
<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>

In response, get a New ID.
You can attach mail through the init.php file by adding an action on the OnAfterIBlockElementAdd event

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question