Issue
Here is my validator for the field article where pdf files should be uploaded:
$validator
->add('article', [
'rule' => [
'extension' => [
['article', 'pdf'],
'message' => 'Only pdf!'
]
]
])
->notEmpty('article');
This gives an error:
"Unable to call method "" in "default" provider for field "article""
How can I fix this to enable uploading only pdf
files to the field article?
Solution
The order of the elements in your code is wrong.
Also worth a look: API Class Validation - Extension
$validator
->add('article', [
'extension' => [
'rule' => [ 'extension', ['pdf'] ],
'message' => 'Only PDF!'
]
])
->notEmpty('article', 'This field is required')
;
You should also check the mimeType to enhance security. Works similar, see also the example in the book in the chapter conditional validation
Answered By - Oops D'oh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.