提交带有空复选框的 HTML 表单 [英] Submit an HTML form with empty checkboxes

查看:32
本文介绍了提交带有空复选框的 HTML 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML 表单 - 使用 PHP,我将表单数据发送到 MySQL 数据库中.表格上的一些问题的答案有复选框.显然,用户不必勾选一个问题的所有复选框.我还想将其他问题(包括广播组)设为可选.

I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make the other questions (including radio groups) optional.

但是,如果我提交包含空框、无线电组等的表单,我会收到一长串未定义索引"错误消息.

However, if I submit the form with empty boxes, radio-groups etc, I received a long list of 'Undefined index' error messages for each of them.

我该如何解决这个问题?谢谢.

How can I get around this? Thanks.

推荐答案

未选中的单选或复选框元素不会被提交,因为它们不被视为 成功.因此,您必须检查它们是否是使用 issetempty 函数发送的.

Unchecked radio or checkbox elements are not submitted as they are not considered as successful. So you have to check if they are sent using the isset or empty function.

if (isset($_POST['checkbox'])) {
    // checkbox has been checked
}

这篇关于提交带有空复选框的 HTML 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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