PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to put line-breaks in Yii2 validation rules messages

 July 12, 2022     line-breaks, message, php, yii2, yii2-validation     No comments   

Issue

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.


Solution

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'],


Answered By - ScaisEdge
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing