防止更改复选框值 [英] Prevent changing checkbox value

查看:181
本文介绍了防止更改复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我没有在网络上找到其他答案,我在这里问:

As I've found no other answer over the web, I'm asking here :

我想找到一种方法来防止人们更改复选框的值。

I'd like to find a way to prevent people from changing the checkboxes' values.

我使用 serialize() unserialize / code>来设置和获取复选框数据通过我的数据库,问题是如果有人更改复选框的值(使用Chrome或Firefox开发工具,exemple),它弄乱我检索的值。所以我想知道是否可能通过PHP。

I'm using serialize() and unserialize() to set and get checkboxes data over my database, and the problem is if someone changes the value of the checkbox (using Chrome or Firefox dev tools by exemple) it messes my retrieved values. So I'd like to know if it is possible via PHP.

推荐答案

这有点不清楚你问:php只处理服务器端的数据。如果你不想要读/写数据库的数据集的某些特定属性被修改,那么就不要这样做。没有人强迫你考虑你获得的数据,例如在从表单提交中获得的$ _POST值内。

It is a bit unclear what you ask: php can only handle data on the server side. If you do not want some specific attribute of a dataset you read / write to / from a database to be modified, then just don't do it. No one forces you to consider data you get, for example inside the $_POST values you get from a form submission.

但是复选框本身只显示在客户端。只有用户可以修改这些值。 php没有任何控制,因为它是在服务器端运行。

However the checkboxes themselves are only presented at the client side. Only there users can modify the values. php does not have any control over that, since it is running on the server side.

您可以做的是尝试通过javascript来阻止对复选框的更改,这可以在客户端使用。这通过抑制或更好地吞咽用户引发的点击事件来工作。但实际上没有必要:html本身允许声明一个复选框为禁用,防止任何修改。

What you could do is try to prevent changes to the checkboxes by means of javascript which can be used on the client side. This works by suppressing or better swallowing the click events raised by the user. But actually there is no need for that: html itself allows to declare a checkbox as disabled which prevents any modification.

如果这不是你想要的,也许是因为光学原因,你可能想通过添加一个隐藏字段覆盖html级别的复选框的值,相同的名称和值。这样,用户所做的修改就不重要了。

If that is not what you looking for, maybe because of optical reasons, you might want to overwrite the value of the checkboxes on html level by adding a hidden field holding the same name and value. That way it is irrelevant what modifications users make.

这篇关于防止更改复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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