duanbei1598 2012-12-13 10:57
浏览 458
已采纳

提交表单后如何保留文件输入值?

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条回答 默认 最新

  • dsfs21312 2012-12-13 11:04
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题