Php 如何更改symfony表单错误消息?
我使用的是symfony1.4 我有一张这样的表格: 验证程序:Php 如何更改symfony表单错误消息?,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我使用的是symfony1.4 我有一张这样的表格: 验证程序: $this->setValidator('name', new sfValidatorString(array('required' => true))); <?php echo $form['name']->renderError() ?> 查看: $this->setValidator('name', new sfValidatorString(array('required'
$this->setValidator('name', new sfValidatorString(array('required' => true)));
<?php echo $form['name']->renderError() ?>
查看:
$this->setValidator('name', new sfValidatorString(array('required' => true)));
<?php echo $form['name']->renderError() ?>
如何将默认的“required”错误消息更改为例如“This field is required”
编辑:另外,如何去除由渲染器()生成的
和标记。方法?我只想显示文本,不需要额外的标记
注:这是一个显而易见的问题,但由于我花了很长时间才找到答案,我认为这个问题不适合在这里提出
new sfValidatorString(array('required' => true), array('required'=>'This field is required'))
您可以通过扩展sfWidgetFormSchemaFormatter来创建自定义WidgetFormSchemaFormatter,以格式化表单输出。1.更改所需消息:
new sfValidatorString(
array(
'required' => true,
),
array(
'required'=>'You custom required message'
));
2.创建一个新的格式化程序类
3.重新定义所需的属性
<?php
class myWidgetFormSchemaFormatter extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '',
$helpFormat = '%help%',
$errorRowFormat = '%errors%',
$errorListFormatInARow = " <ul class=\"error_list\">\n%errors% </ul>\n",
$errorRowFormatInARow = " <li>%error%</li>\n",
$namedErrorRowFormatInARow = " <li>%name%: %error%</li>\n",
$decoratorFormat = '',
$widgetSchema = null,
$translationCatalogue = null;