on my current project I stumbled across the following problem:
I'm building an application that allows visitors to participate in a raffle. There are different types of raffles - one of them is a file upload (so user uploads his favorite vacation picture and has the chance to win something for example).
I'm validating the form (there is just one form for all raffle types which changes depending on type) via a FormRequest which works awesome except for one problem:
If the user uploads a file and makes another mistake (forgetting a required field / wrong captcha etc) I'd like to "cache" the file already so he doesn't have to upload the file on every try. Problem is I don't even get to my controller since the FormRequest already bounces the request back with errors.
Now I'm thinking about doing the caching part in a middleware. Is that the approach to go or is there maybe a better way to save an uploaded file somewhere before FormRequests are validated?
How are you validating the form?
Are you using some kind of ajax upload?
Does the file get uploaded to the server before form gets validated?
From top of my head:
Upload the file
Store its details (id) in users's session together with raffle info (id?)
Pre-populate the form (hidden field) or just send the info back to the form ...
You can't keep files in the request for security reasons. The only option would be using javascript validation, so don't let the user submit the form before everything is correct.