Skip to content

Instantly share code, notes, and snippets.

@ASDAFF
Created September 5, 2019 19:16
Show Gist options
  • Select an option

  • Save ASDAFF/bf3bac198e39b7b77f65b4a0c5d83221 to your computer and use it in GitHub Desktop.

Select an option

Save ASDAFF/bf3bac198e39b7b77f65b4a0c5d83221 to your computer and use it in GitHub Desktop.
Добавка елемента в инфоблок и отправка сообщения на почту AJAX битрикс
$(document).on("click", '#subscribe_submit', function(e) {
e.preventDefault();
var parent = $(this).parent();
$.ajax({
url: '/local/ajax/subscribe.php',
data: {
mail: parent.find('input[name="mail"]').val(),
},
dataType: 'json',
success: function(result){
if(result.error){
alert(result.error);
}else{
alert(result.sendMsg);
}
}
});
});
<?define("NO_KEEP_STATISTIC", true);?>
<?define("NOT_CHECK_PERMISSIONS", true); ?>
<?define("NEED_AUTH", true); ?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); ?>
<?
use Bitrix\Main\Mail\Event;
use Bitrix\Highloadblock as HL;
use Bitrix\Main\Entity;
use Bitrix\Main\Context;
use Bitrix\Main\Config\Option;
CModule::IncludeModule("iblock");
$request = Context::getCurrent()->getRequest();
$mail = $request->get("mail");
if($mail){
$el = new CIBlockElement;
$PROP = array();
$PROP['MAIL'] = $mail;
$arLoadProductArray = Array(
"MODIFIED_BY" => $USER->GetID(),
"IBLOCK_ID" => 3,
"PROPERTY_VALUES"=> $PROP,
"NAME" => $mail,
"ACTIVE" => "Y"
);
if($PRODUCT_ID = $el->Add($arLoadProductArray))
$result['elementId'] = $PRODUCT_ID;
else
$result['error'] = $el->LAST_ERROR;
//отправка почты админу
$arEventFields= array(
"MAIL" => $name
);
if($msg = CEvent::Send("SUBSCRIBE", SITE_ID, $arEventFields, "N", 48)){
$result['sendMsg'] = "Подписка успешно оформлена";
}else{
$result['sendMsg'] = "Ошибка, попробуйте еще раз";
}
}else{
$result['error'] = "Заполните пустые поля";
}
exit(json_encode($result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment