views:

824

answers:

3

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)?

+1  A: 

Add something like this at the top of your template:

foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
  echo $form[$widgetName]->renderError();
}
bb
Great idea, thank you!
James Skidmore
A: 

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; ?>
sjobe
Should also work for 1.1+, I have not tested it but I see no reason why they would not maintain backward compatibility.
sjobe
Thanks for the answer, sjobe. Unfortunately that doesn't work for whatever reason in 1.2.
James Skidmore
+1  A: 

In andvance

<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>
Mailo