Do all form validation errors appear at the top in symfony?

I think I can miss something, which should be relatively general. How can I make all form validation errors, including field-related errors, appear at the top of the form (global)?

+3
source share
3 answers

Add something like this at the top of your template:

foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
  echo $form[$widgetName]->renderError();
}
+5
source

Early

<ul>
  <?php foreach($form->getWidgetSchema()->getPositions() as $widgetName): ?>
    <?php if($form[$widgetName]->hasError()): ?>
    <li><?php echo $form[$widgetName]->renderLabelName().': '.__($form[$widgetName]->getError()->getMessageFormat()); ?></li>
    <?php endif; ?>
  <?php endforeach;?>
</ul>
+1
source

If you are an old school like me (before Symfony 1.1), try

<?php if ($sf_request->hasErrors()): ?>
  <p>Please correct the following errors and try again:</p>
  <ul>
  <?php foreach($sf_request->getErrors() as $name => $error): ?>
    <li><?php echo $error ?></li>
  <?php endforeach; ?>
  </ul>
<?php endif; ?>
0
source

Source: https://habr.com/ru/post/1711115/


All Articles