Home › Forums › Front-end Issues › Frontend form file upload validation › Reply To: Frontend form file upload validation
Hello @acf-support,
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.
Gregor
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.