用于选择消息的收件箱系统复选框
目前,我们正在网站中实施收件箱系统,并希望用户能够选中多条收件箱消息并单击“删除”链接来批量删除它们。
每条收件箱消息在数据库中都有其自己的 ID。
我们需要帮助的是让复选框系统正常工作。我们不知道从哪里开始;我们是否必须给每个人一个 ID 或者用 PHP 填写一些值 - 我们只是不知道。非常感谢任何帮助。
We currently are implementing an inbox system into our website and want a user to be able to checkmark multiple inbox messages and click a Delete link to mass-delete them.
Each inbox message has it's own ID in the database.
What we need help with is getting the checkbox system working. We don't know where to start with it; whether we have to give each one an ID or fill in some value with PHP - we just don't know. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以为所有复选框指定相同的名称(以 [] 结尾)和不同的值,如下所示:
这样,当提交表单时,PHP 会将所有选定的值放入 $_POST 内的数组中。因此,如果在上面的示例中选中顶部和底部复选框,则 $_POST['deletemessage'] 将包含 [367, 405]
You can give all your check boxes the same name, ending in [], and different values like this:
This way, when the form is submitted, PHP will put all the selected values into an array within $_POST. So if the top and bottom check boxes were selected in the example above, $_POST['deletemessage'] would contain [367, 405]
xHTML 表单
PHP
The xHTML form
The PHP
然后,这将返回一个可以循环的数组。
关于安全性的说明,您需要确保消息 ID 与尝试删除消息的用户相关联。
This will then return an array you can loop through.
A note on security, you will want to ensure that the message id is assosciated with the user who is trying to delete the message.
首先为所有复选框指定相同的名称,末尾带有方形 brqackets
somename[]
,然后在提交表单(作为 POST)时
print_r($_POST)
Start by giving all the check boxes the same name with square brqackets at the end
somename[]
and when you submit the form (as a POST) do
print_r($_POST)