Answer the question
In order to leave comments, you need to log in
Why doesn't CIBlockElement::Add() throw errors on required fields?
The following code runs without error, even though 'PROPERTY_VALUES' is missing the required 'EMAIL' property. and if I try to do something similar through the admin panel where the same CIBlockElement::Add() file is processed in the \bitrix\modules\iblock\admin\iblock_element_edit.php file, it will give an error that the property is missing.
$add = new \CIBlockElement();
$data = [
'IBLOCK_ID' => 7,
'ACTIVE' => 'Y',
'NAME' => date('d.m.Y H:i') ,
'PROPERTY_VALUES' => [
'NAME'=> 'Имя',
'PHONE'=> '322-223-322'
]
];
$id = $add->Add($data);
if (!$id) {
throw new \Exception($add->LAST_ERROR);
}
Answer the question
In order to leave comments, you need to log in
Understood. In CIBlockElement::Add(), checking for properties works differently.
it only checks the validity of the passed properties in 'PROPERTY_VALUES'. That is, so that she swears that (Required property "###" is not filled). It must be given to 'PROPERTY_VALUES' with an empty value.
It also does not check the user's write permissions, they must be checked separately via \CIBlock::GetPermission().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question