Answer the question
In order to leave comments, you need to log in
[[+content_image]]
YII2 - How to set custom message for "Image" validation rule?
Can't set custom message for 'image' validation rule.
No matter what I do, the message "The file "test.jpg" is not an image."
Code example:
public function rules()
{
return [
[['photoFacet', 'photoProfile'], 'required', 'message' => 'This field can not be blank'],
[['photoFacet', 'photoProfile'], 'image', 'message' => 'My own message']
];
}
Answer the question
In order to leave comments, you need to log in
As evgenybuckharev said, you set the wrong one. We read the docs
:
www.yiiframework.com/doc-2.0/yii-validators-imagev... we see the
$notImage
property in the Public Properties ,
we read the docs to it: www.yiiframework.com/doc-2.0/ yii-validators-imagev...
we understand, we excite the neural activity of the brain for 2 minutes:
public function rules()
{
return [
[['photoFacet', 'photoProfile'], 'required', 'message' => 'This field can not be blank'],
[
['photoFacet', 'photoProfile'],
'image',
'message' => 'My own message',
'notImage' => 'My not image message'
]
];
}
\yii\validators\ImageValidator
We look at this file and see that the given text of the message changes in the public property notImage
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question