K
K
KerryDarko2016-04-07 19:33:47
symfony
KerryDarko, 2016-04-07 19:33:47

What can I do to prevent the user from re-uploading the file if the form does not pass validation for another field?

I'm not asking you to lay out a clean solution for me, only confirmation, one way or another I think.
There is a form: couple of fields and a field for a file.
If the form did not pass validation for some field (not for the file), then when this form is displayed with errors, this file should be displayed as already loaded, which, of course, can be replaced with another one if desired.
Is there a feature in Symphony that can do this for you? Or a ready-made bundle?
If not, does that make it just a file upload regardless of the validation? It annoys me that if the user in this case just spit and closes the page, then downloaded unnecessary pictures will begin to accumulate.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Nikolaev, 2016-04-07
@Heian

I somehow made that the image is loaded by Ajax after the client and server validation of the fields has passed. Of the obvious disadvantages - it is more difficult to manage, but there is no need to delete pictures.
You can make it load in any case (to the temp folder), after server validation, move the image from temp to the destination folder, and clean the temp folder once a day with cron.

A
Andrew Vakulenko, 2016-04-08
@pro100ShCoder

If this option is suitable - validation on js. If it is important to check on the server - send data by Ajax, if ok we do the form loading.
You can also use the File API to validate a file on the client side and / or send a form with files with Ajax and already check on the server side - FormData
examples of reading files on the client side

T
ThunderCat, 2016-04-07
@ThunderCat

Session, other options seem unnecessarily complicated to me.
When submitting the form, we load the picture, remember the path to the session, if there is no picture - we fumble in the session - is there a picture? - ok, no - it's not scary either, check the data, if it's wrong - return to the form, check if there is an image url in the session, show if there is.
PROFIT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question