When you have restricted file types in a file field, ACF accepts them as uploads on the front-end and reports a file has been uploaded.
Here’s the setup:
front end acf_form on public page
file field (not set as required)
file field “type” is restricted (such as “PDF”)
acf/save_post action in functions.php sends an e-mail notification
Open form. Upload non-approved file type (such as “DOC”). Front end returns “success” page instead of validation error. Then, via acf/save_post action, get_field([file field], $post_id) returns something that evaluates to true.
After that, correctly, ACF discards the file. It is not stored in WordPress’ media library.
I think I know why this is happening, but it doesn’t seem like desired behavior.
So basically the validation for allowed file types occurs too late when using a front-end form with
Do you have the latest version of WP and ACF PRO?
Yes, that sounds like another good way to describe it.
WP 4.3 and ACF Pro 5.3.0
I’ll assign this topic to @elliot so he’s notified of it.
Is this going to be fixed soon?
Our image field gets the validation message in the post meta where the image should be.
I think this a problem with file validation in general.
My form creates a new post in a custom post type. The file upload field is required. When a file with a non-approved format is uploaded, ACF does not save the information as a new post but does return a success message to the user, meaning they have no idea there’s anything wrong with it.
Same here. Happens with the “basic uploader” inside a front end form. But instead of a post, I’m saving user meta values.
1. File upload field is required.
2. A file with a non-approved format is uploaded.
3. Front end form is submitted and redirects to the URL defined inside the “return” parameter. User doesn’t know anything is wrong.
I’m utilizing “acf/upload_prefilter” now to prevent the redirect, but haven’t figured out how to display the error messages in the front end after the page has loaded.
The problem also seems to be related to this post.
Thanks in advance!
I’ve added this one to my to-do but doesn’t sound like it will be an easy or simple fix
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.