简体   繁体   中英

How to customise error message to add ID in Yii?

Currently I am using $form->error($user_model,'password') this function to show error message which gives me output as <div class="errorMessage">Please enter current password</div> but I want to add id in same div. What changes I have to do for that?

To customize error message you have to go to user model and change/add your message to function rules() array.

function rules() {
   return [
      ['password', 'required', 'message' => 'Your custom message'],
   ];
}

Check CRequiredValidator class for more information.


To apply some custom ID:

$form->error($error_model, 'password', ['id' => 'My-super-custom-id']);

just it will break your error messages output when using yii-js methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM