arccuks
arccuks

Reputation: 173

Yii2 validators don't show message

Can someone tell me what i am doing wrong here?

// Some other validation rules
[['FILE_BLOB'], 'file' , 'maxSize' => 1024 * 1024, 'message' => 'Here goes my message'],
//Some more validation rules

Well my problem is that validator works fine, but it shows it's inbuilt errorMessage in case i want to upload bigger files. Not the one that i specified in 'message' => 'Here goes my message'

And how can i get my own errorMessage in case there are 2 validators?!

[['FILE_BLOB'], 'file' , 'extensions' => ['pdf','text'], 'maxSize' => 1024 * 1024],

I guess the easy way would be to split validations like this:

[['FILE_BLOB'], 'file' , 'maxSize' => 1024 * 1024],
[['FILE_BLOB'], 'file' , 'extensions' => ['pdf','text']],

But 1st i need to get to work these messages.

EDIT:

Problem solved. Need to be more careful with reading documentation. For custom message with file size need to use 'tooBig' or 'tooSmall', but for extension custom message need to use 'wrongExtension'.

Upvotes: 0

Views: 502

Answers (1)

Chinmay Waghmare
Chinmay Waghmare

Reputation: 5456

Try tooBig and tooSmall property:

[['FILE_BLOB'], 'file' , 'maxSize' => 1024 * 1024, 'tooBig' => 'message when file size is large'],

For more details refer link

Upvotes: 4

Related Questions