刷新时,表单文件输入会被清除 [英] form file input get cleared when refresh

查看:170
本文介绍了刷新时,表单文件输入会被清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在,如果某个文本输入发生错误(如果有一个文本输入出现错误当用户点击提交按钮[客户端 - >服务器(php) - >客户端]时,文件输入的内容被清除,这是令人讨厌的!



当页面提交错误时,我使用最后一个值设置了其他文本输入,但我无法使用文件输入。我试图用 document.getElementsByName('logo')[0] .value; 来设置文件输入值以将其设置为隐藏值,但我得到了路径C :\fakepath\random-0690.JPG...这是如此令人震惊,我知道它出于安全目的,但它是令人震惊的...



可以解决吗?感谢。

解决方案

我找到了答案!

,我创建了一个AJAX调用来发送表单内容并验证一切是否正常。然后,如果有错误,请显示这些内容(并且它会将值和文件附件保留在表单中)。否则:发送帖子表单和附加文件。


I have a html form with some text input and a file input (image logo).

Now, if there is an error with one of the text inputs (like length is invalid) when the user click the submit button [client->server(php)->client], the content of the file input is cleared which is annoying!

I set others text input with last values when the page submits with an error, but I cant with a file input. I tried to set the file input value with document.getElementsByName('logo')[0].value; to set it in a hidden value but I got the path "C:\fakepath\random-0690.JPG"... this is so shocking, I know its for security purposes but it is shocking...

How i can resolve that? Thanks.

解决方案

I found the answer !

This is simple, I created an AJAX call that send the form contents and validate if everything is okay. Then if there are errors, display these (and it will keep the values and file attachments in the form) .. Else : Send the post form and the attached file.

这篇关于刷新时,表单文件输入会被清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆