Html 如何发送隐藏数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17505726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send hidden data
提问by user2556079
I have a form(like the one below for example) where I type data, but I also want to send data which are not directly entered by the user, for example a generic Id(for a user in this case)
我有一个表单(例如下面的表单),我在其中输入数据,但我也想发送用户未直接输入的数据,例如通用 Id(在这种情况下为用户)
<form name="input" action="" method="post">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
Don't know if I have been clear enough, I hope so.
不知道我说的够不够清楚,希望如此。
回答by Mgetz
try a hidden
input:
尝试hidden
输入:
<input type="hidden" value="foo" name="user_id" />
The user can't see it, but remember that such inputs can be spoofed and need to be validated on the server just like any other input.
用户看不到它,但请记住,此类输入可以被欺骗,并且需要像任何其他输入一样在服务器上进行验证。