本文介绍了表单提交后如何保留文件输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么似乎是一个相当基本的问题,并想确认如何最好地处理它。我有一个表单,其中一个输入是一个文件输入。在提交表单时,会有一些PHP验证检查,以确认所有必填字段已经填写完毕(如果不是的话,它会通知用户填写剩下的部分,并再次显示表单,而不会提交它)。这一切都很好,但如果用户选择了一个文件,那么我不相信有任何由于浏览器的安全设置保持所选文件在输入。



结果唯一的方法,我可以看到保持文件输入是要么将其存储在服务器上的初始提交(即使其他字段不完整),然后将其与正确提交时提交关联。或者使用Javascript来验证表单,以便在完成之前不会实际提交(所以文件输入不需要以编程方式设置)。



上午我在这里错过了一些东西,还有另外一种处理方法,或者说我只能说这是唯一的两个选择?

谢谢你们!



Dave

解决方案

我想你已经提出了你的问题的答案。它应该更好地验证表单的其他领域使用AJAX,并不提交最初的文件。 anbd如果你有一些文件的问题,你可以有一些基本的检查你的文件使用类似的文件扩展名使用AJAX


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

解决方案

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

这篇关于表单提交后如何保留文件输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:28
查看更多