Home › Forums › Front-end Issues › Frontend form file upload validation › Reply To: Frontend form file upload validation
I have to come back to this issue again because of two reasons:
1. The problem with the basic uploader and the code snippet you provided above is, that it only works, when a file has not been uploaded already. If, in any case, the user returns back to the form, leaves the upload-field unchanged, clicks the submit button again, the upload field returns an ID as value (the attachment ID of the file) instead of the path to the already uploaded file. So the validation of the file extension fails, because it’s not able to fetch the file.
The upload-field is set to return the attachment url in the ACF-setup, not the ID.
To work around this, I’m now checking whether the field value is an ID or a path via Regex and catch the file with “wp_get_attachment_url” if it’s an ID.
2. If the user selects a file with a file size that is above the limit in the setup of that field, the front end form doesn’t spit out the validation error (File is too large). Instead it proceeds and redirects to the given URL in “return” parameter. Basically the same problem as with file extension checking.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.