Yii2 errorOptions编码false在ActiveForm中不起作用 - 错误消息中的HTML

时间:2017-01-16 04:45:07

标签: yii2

在规则中,我有一个带有html文本的自定义消息:

[ 'user_email', 'required', 'message' => 'Don\'t have one? <a href="/contact-us">Give us a call</a>' ],

我的表格:

<?php $form = ActiveForm::begin( [
    'enableAjaxValidation' => true,
    'validationUrl'        => '/user/validate-register',
] ); ?>

<?= $form->field( $model, 'user_email', [
        'errorOptions' => [
            'encode' => false,
        ]
] )->textInput( [ 'maxlength' => true ] ) ?>

当我输入errorOptions时,不会显示错误消息...它突出显示为红色,但不显示内联消息。

没有errorOptions消息,html被编码 html not encoded

使用errorOptions时,不会显示任何错误消息

no error message at all

1 个答案:

答案 0 :(得分:6)

添加课程help-block以正确应用css。

<强>表格

$form = ActiveForm::begin([
   'fieldConfig' => [
      'errorOptions' => [
           'encode' => false,
           'class' => 'help-block'
       ],
   ],
]);

字段

<?= $form->field( $model, 'user_email', [
    'errorOptions' => [
        'encode' => false,
        'class' => 'help-block'
    ]
])->textInput( [ 'maxlength' => true ] ) ?>