How to put line-breaks in Yii2 validation rules messages

拜拜、爱过 提交于 2019-12-12 12:14:50

问题


I need to break a long message used in Yii2 validation rule.

I tried like this:

public function rules()
{
    return [
        ['username', 'required', 'message' => 'long message first line here'."<br>".PHP_EOL.'long message last line here'],
    ];
}

but the <br> appears in the message and the line doesn't break where I need.

Just to be clear, what I get is:

 long message first line here<br>long message last line here

and not:

 long message first line here
 long message last line here

Anyone who can help with this? I'd be really grate! Thank you in advance.


回答1:


I have solved adding this to ActiveForm::begin

<?php $form = ActiveForm::begin([

        'fieldConfig' => [
            'errorOptions' => ['class' => 'help-block', 'encode' => false],
    ],

]); ?>

and with a simple <br />

 [['username'], 'required', 'message' => 'long message first line here <br />long message last line here'],


来源:https://stackoverflow.com/questions/34581181/how-to-put-line-breaks-in-yii2-validation-rules-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!