How to put line breaks in Yii2 validation rule messages

I need to break the long message used in the 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 a message appears in the message <br>and the line does not break where I need to.

To be clear, I get:

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

and not:

 long message first line here
 long message last line here

Who can help with this? I would be very grateful! Thank you in advance.

+4
source share
1 answer

I decided to add this to ActiveForm :: begin

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

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

]); ?>

and with simple <br />

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

Source: https://habr.com/ru/post/1622646/


All Articles