Make all form validation errors show up at top in symfony?
Question
I think I may be missing something here that should be relatively common. How can I make all form validation errors, including field-bound errors, show up at the top of the form (global)?
Solution
Add something like this at the top of your template:
foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
echo $form[$widgetName]->renderError();
}
OTHER TIPS
In advance
<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>
If you're 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; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow