Type 'file' field validation - Does not work on Frontend Form?

Support General Type 'file' field validation - Does not work on Frontend Form?Resolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #49204
    CodogCodog
    Participant

    Hi there,
    following your validation documentation here: https://docs.metabox.io/validation/ I used your suggested methodology to add disallowed file type validation on a 'type'=> 'file' custom field like this:

    
    'fields'     => [
        [
            'name' => 'Uploaded Files',
            'id'   => 'my_files',
            'type' => 'file',
        ],
    ],
    'validation' => [
        'rules'    => [
            '_file_my_files[]' => [
                'extension' => 'pdf',
            ],
        ],
        'messages' => [
            '_file_my_files[]' => [
                'extension' => 'file extension not allowed',
            ],
        ],
    ],
    

    Strictly following the validation page instructions - On my MB Frontend Form, using this method, I do not see any validation feedback on my custom field when the file type is PDF? Can you confirm this works for you at your end on a frontend form?

    Cheers

    #49211
    CodogCodog
    Participant

    Not to worry, I wrote my own jQuery validation callback for file extensions. Although I am still curious to understand why the above does not?

    #49234
    PeterPeter
    Moderator

    Hello Leo,

    Thanks for reaching out.

    If you use the validation setting extension, that means you only allow the given file extension. In this case, it is a PDF file and you don't see the error message when uploading the PDF file.
    If you upload another file type like .png, .doc ... you will see the error message. Can you please confirm this?

    #49235
    CodogCodog
    Participant

    Hi Peter,
    thanks for getting back to me. I did try the opposite as you suggested (uploading an alternate file type like a PNG) to return any response from the validation. But that also did nothing for me?

    Cheers

    #49246
    PeterPeter
    Moderator

    Hello,

    It works well on my demo site so I think the JavaScript validation could be affected by another plugin or custom code on your site. You can try to deactivate all other plugins, switch to a WordPress theme and see if it helps.

    #49247
    CodogCodog
    Participant

    Hi Peter,
    thanks for your response. Ok, good to know. If I need to use this methodology in the future I'll be sure to test for any conflicts.

    Thanks

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.