A
A
Alex2016-05-11 14:02:17
1C-Bitrix
Alex, 2016-05-11 14:02:17

How to display errors of individual fields in Bitrix?

Hello, there is such a method in the documentation,
<?=$FORM->ShowFormErrors()?>
but it displays errors for all fields in a list.
Is it possible to display an error of a separate field? And is it possible to add class='error' to the corresponding input

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
no_one_safe, 2016-05-11
@no_one_safe

Web form (complex component)
In the settings there is a parameter responsible for extended error output:
In result_modifier.php run through all the fields that have an error (in $arResult["FORM_ERRORS"] ) and change the html for the corresponding questions:
In result_modifier.php component form.result.new

if (is_array($arResult["FORM_ERRORS"])){
   foreach($arResult["FORM_ERRORS"] as $FIELD_SID => $BITRIX_ERROR_TEXT){
      $arQuestion = $arResult["QUESTIONS"][$FIELD_SID];
         if(strpos($arQuestion['HTML'],'class') !== false){
               $arQuestion['HTML'] = str_replace('class="','class="error ',$arQuestion['HTML']);
         }
         else{
               $arQuestion['HTML'] = str_replace('name=',' class="error" name=',$arQuestion['HTML']);
         }
      $arResult["QUESTIONS"][$FIELD_SID] = $arQuestion;
   }
}

C
cubania, 2018-10-31
@cubania

Всю голову сломал из-за того, что класс не добавлялся. В коде в result_modifier.php нужно указывать не $arQuestion['HTML'], а $arQuestion['HTML_CODE'] и тогда класс "error" дописывается

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question