I have this custom form which allows user to upload files. managed_file field is used for this purpose. Now I want to validate the uploaded file content (eg. check virus) after user submit the form. How do I clear the file field that it only display an empty file upload widget in the form after the validation fails?

Comments

yangli0516’s picture

As a workaround, I added another hidden manged_file field in the form. The purpose of this is to get empty file upload widget render array from $form variable. So when the validation fails, pass the hidden field value in $form variable to the field to clear.

This seems does the trick. But I am wondering if there's any other elegant ways.