Answer the question
In order to leave comments, you need to log in
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
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;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question