提交一个带有空复选框的HTML表单 [英] Submit an HTML form with empty checkboxes
问题描述
我有一个HTML表单 - 使用PHP,我将表单的数据发送到MySQL数据库。一些对表单上的问题的答案有复选框。显然,用户不必勾选一个问题的所有复选框。
但是,如果我提交空白框,无线电广播组等形式,我收到了一个长的
如何解决这个问题?感谢。
未提交的未经检查的收音机或复选框元素不会被视为成功。因此,您必须检查是否使用 isset
或空
函数发送。
if(isset($ _ POST ['checkbox'])){
//复选框已选中
}
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.
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屋!