4

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.

danicotra
  • 1,333
  • 2
  • 15
  • 34

1 Answers1

6

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'],
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Oh yeah! Accepted as the solution! I was trying to use [encodeErrorSummary](http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#$encodeErrorSummary-detail) for this `'encodeErrorSummary' => false` but, I can't understand why, it seems useless ?? – danicotra Jan 03 '16 at 23:12