“保护"来自输入的文本框值(HTML 表单) [英] "Protect" text box value from input (HTML form)

查看:30
本文介绍了“保护"来自输入的文本框值(HTML 表单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以为 HTML 文本框赋值并保护它.

I was wondering whether it is possible to assign a value to an HTML text box and protect it.

我的意思是让它的内容不可修改,这样当表单被提交时,我确定"提交的是这个值.

What I mean is make it´s content unmodifiable, so that when the form gets submitted im "sure" it was this value which was submitted.

顺便说一句,我意识到更简单的方法不是听"这个输入,而是分配它,但是如果能够做上面所说的事情,它会派上用场.

BTW I realize the easier way would be not to "listen" fot this input and just assign it but it would come in handy to be able to do what´s stated above.

我希望问题足够清楚,请提出任何需要的说明.

I hope the question is clear enough, please ask for any needed clarification.

提前致谢!

我肯定不够清楚,但我试图表示我应该在提交后保留该值(在客户端不可修改)

I was definitely not clear enough but I tried to express that i should hold the value after submitted (not modifiable in client side)

推荐答案

不,不是.您永远不应该相信用户输入,包括表单提交.

No, it's not. You should never trust user input, which includes form submissions.

其他答案告诉您如何将字段标记为只读.如果您想显示特定值,同时显示它不是打算编辑的,这很有用.

The other answers tell you how to mark the field as read-only. This is useful if you want to display a particular value, while showing that it's not intended to edited.

但是,它仍然可以通过 Firebug、DOM Inspector 等进行修改.或者,他们可以不使用浏览器而直接提交 HTTP 请求.

However, it can still be modified with Firebug, DOM Inspector, etc. Or, they can just submit a HTTP request without using the browser at all.

我建议将值存储在会话中.

I would recommend storing the value in a session instead.

这篇关于“保护"来自输入的文本框值(HTML 表单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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