How to retain file input value after form submission with errors?

隐身守侯 提交于 2019-12-10 15:21:33

问题


I have what seems to be a rather basic question and wanted to confirm how best to deal with it. I have a form with a number of inputs one of which is a file input. On submission of the form there are a number of validation checks in PHP to confirm all necessary fields have been filled out as they should have been (and if not then it notifies the user to fill out the remainder and shows them the form again without submitting it). This is all fine but if a user has selected a file then i don't believe there's anyway of keeping the selected file within the input due to browser security settings.

As a result the only way i can see to keep the file input is to either store it on the server on initial submission (even if the other fields aren't complete) and then associate this with the submission when it's submitted correctly. Or to use Javascript to validate the form so it isn't actually submitted until it's completed (so the file input doesn't ever need to be set programatically).

Am I missing something here and there's another way of dealing with this or am i right in saying these are the only two options?

Thanks guys!

Dave


回答1:


i think you already suggested the answer to your problem . it owuld be better to validate other fields of the form using ajax and don't submit the file initially. anbd if you have some problems with the file you can have some basic checks for your file using like file extension using ajax



来源:https://stackoverflow.com/questions/13858347/how-to-retain-file-input-value-after-form-submission-with-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!