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)?
我想我可能会遗漏一些应该比较常见的东西。如何将所有表单验证错误(包括字段绑定错误)显示在表单顶部(全局)?
3 个解决方案
#1
Add something like this at the top of your template:
在模板顶部添加以下内容:
foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
echo $form[$widgetName]->renderError();
}
#2
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>
#3
If you're old school like me (before Symfony 1.1), try
如果你像我这样的老学校(在Symfony 1.1之前),试试吧
<?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; ?>
#1
Add something like this at the top of your template:
在模板顶部添加以下内容:
foreach($form->getWidgetSchema()->getPositions() as $widgetName)
{
echo $form[$widgetName]->renderError();
}
#2
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>
#3
If you're old school like me (before Symfony 1.1), try
如果你像我这样的老学校(在Symfony 1.1之前),试试吧
<?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; ?>