改变输入文件的值 [英] Changing the value of input file

查看:106
本文介绍了改变输入文件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两个问题澄清了输入文件的值由于安全原因无法更改。





在PHP中,当验证表单时,其中一种常用方法是重新填充在点击提交按钮之前提供的输入文本中输入的值,以便客户端知道他所插入的内容,或者只是为了保持字段中的值,这是客户期望的。 (每次出现特定错误时,他都不必重新填写表单)。



因此,我们使用以下内容:

 < input type =textname =titleid =titlemaxlength =100value =<?php echo htmlspecialchars($标题);?>中/> 

因为我无法更改输入文件的值,所以我可以用提供的路径 $ image ['tmp_name'] 重新填充它,这意味着客户端将不得不重新上传浏览)每次验证出现错误时的图像,是不是有任何可能的方法来保持该值? 解决方案

使用javascript您可以阻止提交表单,直到所有字段都得到验证。



我建议 jQuery验证引擎教程。 演示



另外你可以使用 jQuery文件上传为图片上传器添加一些样式。



当然,必须在服务器上验证一些字段,这就是为什么您可以使用验证引擎发布ajax请求。

 ajaxUserCall:{
url:ajaxValidateFieldUser,
extraData:name = eric,
alertText:* This user已被占用,
alertTextOk:*用户有效,
alertTextLoad:*正在验证,请等待
},

使用服务器端验证重定向或刷新的一些示例:演示


The following two questions clarify that the value of input file cannot be changed due to security reasons.

In PHP, when validating a form, one of the usual approaches is to re-fill the entered value in input text that was provided before clicking the submit button, so that the client knows what he inserted, or simply to keep the values in the fields, which is what the client is expecting. (He won't have to re-fill the form every time when there's a specific error).

So we use the following:

<input type="text" name="title" id="title" maxlength="100" value="<?php echo htmlspecialchars($title);?>" />

So since I cannot change the value of the input file, so I can re-fill it with the provided path $image['tmp_name'], this means the client will have to re-upload (or re-browse) the image each time a validation goes wrong, isn't there any possible way to keep that value?

解决方案

Using javascript you can prevent the form from being submitted until all fields are validated.

I recommend jQuery Validation Engine tutorial included. demos

Also you can add some style to the image uploader using jQuery file upload.

Of course some field must be verified on the server that's why you can post an ajax request with the validation engine.

"ajaxUserCall": {
    "url": "ajaxValidateFieldUser",
    "extraData": "name=eric",
    "alertText": "* This user is already taken",
    "alertTextOk": " * User is valid",
    "alertTextLoad": "* Validating, please wait"
},

Some example with server side validation witout redirection or refreshing : Demo

这篇关于改变输入文件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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