File extension validation not working
Support › Meta Box AIO › File extension validation not working
- This topic has 5 replies, 2 voices, and was last updated 3 years, 7 months ago by
[email protected].
-
AuthorPosts
-
September 9, 2021 at 11:04 PM #30687
[email protected]
ParticipantHi,
I'm having troubles with the file extension validation in a frontend form. Here's the code with the only relevant field.
add_filter( 'rwmb_meta_boxes', 'nvf_register_mb_candidatura_form_input' ); function nvf_register_mb_candidatura_form_input( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Input Formulário', 'nvf-gb-front' ), 'id' => 'candidatura-form-details', 'post_types' => ['candidatura_bolsa'], 'fields' => [ [ 'name' => __( 'Upload Requested Files', 'nvf-gb-front' ), 'id' => $prefix . 'uploaded_files', 'type' => 'file', 'max_file_uploads' => 20, 'force_delete' => true, ], ], 'validation' => [ 'rules' => [ $prefix . 'uploaded_files' => [ 'extension' => 'pdf', ], ], 'messages' => [ $prefix . 'uploaded_files' => [ 'extension' => 'file extension not allowed', ], ], ], ]; return $meta_boxes; }
Any clue on how to make it work?
I'm using MB AIO Version 1.14.3 and MB Version 5.4.6
Thanks in advance.
September 10, 2021 at 2:00 PM #30692Long Nguyen
ModeratorHi,
Thank you for your feedback.
I've escalated this issue to the development team to fix it in the next update.
September 13, 2021 at 9:20 AM #30719Long Nguyen
ModeratorHi,
The validation feature uses jQuery to check the input name instead of the input ID (field ID) so please change a little bit of the field ID in the
rules
for two fieldsfile
andimage
to this'_file_' . $prefix . 'uploaded_files[]'
. The code should be:add_filter( 'rwmb_meta_boxes', 'nvf_register_mb_candidatura_form_input' ); function nvf_register_mb_candidatura_form_input( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Input Formulário', 'nvf-gb-front' ), 'id' => 'candidatura-form-details', 'post_types' => ['candidatura_bolsa'], 'fields' => [ [ 'name' => __( 'Upload Requested Files', 'nvf-gb-front' ), 'id' => $prefix . 'uploaded_files', 'type' => 'file', 'max_file_uploads' => 20, 'force_delete' => true, ], ], 'validation' => [ 'rules' => [ '_file_' . $prefix . 'uploaded_files[]' => [ 'extension' => 'pdf', ], ], 'messages' => [ '_file_' . $prefix . 'uploaded_files[]' => [ 'extension' => 'file extension not allowed', ], ], ], ]; return $meta_boxes; }
September 16, 2021 at 9:48 PM #30798[email protected]
ParticipantThank you for your support. The validation field messages are working now.
However, contrary to what happens with the other jQuery validation rules, these errors on the uploaded file extensions do not prevent a successful form submission, ending up with all files in the DB. Making the field required had no effect.
Any clue of that might be happening?
September 17, 2021 at 11:15 AM #30805Long Nguyen
ModeratorHi,
I will check that issue and get back to you later.
September 29, 2021 at 12:55 AM #31055[email protected]
ParticipantHi, Long.
I was wondering if you had any updates on this topic?
We're getting closer to deliver the project to the client. Is there any workaround you would recommend in case there's no fixing of this bug by the dev team meanwhile?
Thanks,
Henrique -
AuthorPosts
- You must be logged in to reply to this topic.