禁用复选框
我的表单中基本上有几个复选框,它们不是数据库项,而是根据数据库列检索源值。
由于我不希望用户能够更改这些复选框,因此我禁用了这些复选框。
当我查询记录时,启动时的表单会毫无问题地检索复选框的值。
问题是,当我在提交页面时在表单上遇到验证错误时,最初检索为“Y”(即选中)的复选框值现在为空。
发生验证错误时如何维护这些值?
I basically have a couple of checkboxes in my form, that are not database items but am retrieving the source value based on a database column.
As I do not want the user to be able to change these checboxes, I have disabled these checkboxes.
When I query a record, the form at start-up retrieves the value for the checkbox with no issues.
The problem is, when I hit a validation error on my form when the page is submitted, my checkbox values that were originally retrieved as 'Y', i.e checked are now null.
How can I maintain these values when a validation error occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
禁用的控件不会成功(这就是
禁用
的要点)。要么使用
readonly
控件,要么使用hidden
输入。A disabled control will not be successful (that's the point of
disabled
).Either go with a
readonly
control instead, or use ahidden
input.您可以在发布表单之前启用相关复选框。然后它们将被“刚刚送回”,(希望)完好无损。
与往常一样,您必须进行服务器端检查,并且不要期望表单值和/或 javascript 未被篡改。
You can enable the checkboxes in question just before you post the form. Then they will be "just sent back", (hopefully) untouched.
As always, you must do your server side checks and not expect that form values and/or javascript have not been tampered with.