Support

Account

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