Search code examples
validationlabelmessageyii2rules

Yii2 - How to add custom error messages on input fields


In my database I named 'password' as 'password_hash' so automatically I'd get 'password_hash' in my error message, even tho I changed the label to 'Current password'.

Example:

enter image description here

What I want is:

enter image description here


Solution

  • So basically all I did was add

    'message' => 'Current password cannot be blank.' 
    

    to my rules.

    Make sure you seperate the correct rules, so you don't get that message on multiple fields, where it doesn't make sense. Also make sure you add it on the 'required' rule, unless you want that message to show when it's another rule..

    I hope this helped you guys, as I spent a bit too much time searching for it.