N
N
Nikolai2018-06-05 17:33:36
PHP
Nikolai, 2018-06-05 17:33:36

Where is the php foreach error?

<?if (count($arResult["ERRORS"]) > 0)
  foreach ($arResult["ERRORS"] as $key => $error) 
    if (intval($key) == 0 && $key !== 0):?>
      <div class="alert alert-danger" role="alert">
    <?$arResult["ERRORS"][$key] = str_replace("#FIELD_NAME#", "&quot;".GetMessage("REGISTER_FIELD_".$key)."&quot;", $error);
      ShowError(implode("<br />", $arResult["ERRORS"]));
    ?>
  </div>
    <?elseif($arResult["USE_EMAIL_CONFIRMATION"] === "Y"):?>
      <p><?echo GetMessage("REGISTER_EMAIL_WILL_BE_SENT")?></p>
<?endif?>

Now like this:5b16a4a5a1aa3388597965.png
It is necessary that each error be in a separate alert block

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ice, 2018-06-05
@nikolay_akhmetyanov

It is necessary that each error be in a separate alert block

Try iterating over the array $arResult["ERRORS"] not to shove the same data into it and after that, output this heap at each turn of "ShowError();" to the screen.
It's better to withdraw immediately
<div class="alert alert-danger" role="alert">
<?echo str_replace("#FIELD_NAME#", "&quot;".GetMessage("REGISTER_FIELD_".$key)."&quot;", $error);?>
</div>

or, in the loop, enter into a separate variable / add to the current one, and after the loop, display it with your ShowError() function;

D
Dmitry Kim, 2018-06-05
@kimono

You have non-closed constructions ifand foreach.

<?php if (count($arResult["ERRORS"]) > 0) : ?>
    <?php foreach ($arResult["ERRORS"] as $key => $error) : ?>
        <?php if (intval($key) == 0 && $key !== 0) : ?>
            <div class="alert alert-danger" role="alert">
            <?php
                $arResult["ERRORS"][$key] = str_replace("#FIELD_NAME#", "&quot;".GetMessage("REGISTER_FIELD_".$key)."&quot;", $error);
                ShowError(implode("<br />", $arResult["ERRORS"]));
            ?>
            </div>
        <?php elseif ($arResult["USE_EMAIL_CONFIRMATION"] === "Y") : ?>
            <p><?php echo GetMessage("REGISTER_EMAIL_WILL_BE_SENT") ?></p>
        <?php endif; ?>    
    <?php endforeach; ?>
<?php endif ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question