A
A
Aleksandr Yurchenko2022-04-12 13:30:59
PHP
Aleksandr Yurchenko, 2022-04-12 13:30:59

How to save the file when submitting the form (in case the form is not valid)?

Hello.

Perhaps someone solved a similar problem, could share their experience. There is a project on symfony 2 (I give the framework in case there is some ready-made solution - I could not find it).

It is necessary to implement the saving of attached files (up to 10 files can be attached to the form), if the form did not pass validation when submitting it.

Perhaps there is some ready-made solution (within the package for symfony, or in php). I have not encountered this issue before.

There is an assumption that attached files must be saved in a temporary directory when submitting them, and if the form does not pass validation, attach files back, but in practice it has not yet been possible to implement. I would be grateful for any advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2022-04-12
@ThunderCat

The most logical option seems to be validating the fields with Ajax, and if everything is ok, submit the form with Javascript.
Alternatively, send everything via Ajax, and if successful, just redirect to the desired route, but in this case you will have to bother with the files - wait until they load, delete if the form is not valid ... Or a hybrid option - send fields without files if everything is ok - send files with Ajax, then redirect, IMHO the most sensible option, both in terms of logic and resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question