I'm building a complex file upload form. This form exists of normal data and a set of 4 filetypes with multiple file uploads possible per type.
- ReportForm
- Attachments
- Reports (collection of UploadedFile Entities)
- Photos (collection of UploadedFile Entities)
- Attachments
The UploadedFile entity has a filename, description etc..
Use case: Now, I'm submitting the form with 4 Photos and 2 Reports, all 6 files are ok. But there are some other errors in the form. But I want to show the uploaded files again so that the user doesn't have to reupload them again. These files are already persisted, so when I come back to the same page with a GET, files are shown correctly.
What I already did/tried:
- Before I bind the request I clone the existing uploaded files
- After binding the form I upload all new files (if any) and persist them
- After that I re-add existing uploaded files (from the cloned object). I created form inputs with the existing file id's in, so I can recognise the existing items.
That's all working fine, BUT since I change my Report and Attachments AFTER the bind the data shown after a post can't be changed. I can't do setData($report) on a submitted form.
So existing files aren't show anymore as the form data is still the old report object (from the post).
When I do a normal GET of the page, the $report is retrieved from the database and is shown correctly. But after a POST with already uploaded files, the database data is correct but the form view doesn't know anything about changed data (after the bind).
Any ideas? Or a better way to do this?