【发布时间】:2020-06-15 05:41:29
【问题描述】:
我有一个包含姓名、电台和电子邮件的表格。
<form action="index.php" method="POST" role="form">
<input class="form-control" name="name" type="text" placeholder="NAME">
<input class="form-control" name="email" type="text" placeholder="EMAIL(optional)">
<input type="radio" class="form-check-input" name="gender" value="male">Male
<input type="radio" class="form-check-input" name="gender" value="female">Female
<input type="radio" class="form-check-input" name="gender" value="other">Other
...
为了测试姓名、电子邮件或电台是否填写,我使用isset
if (isset($_POST['name'])) {
echo 'name isset';
}
if (isset($_POST['email'])) {
echo 'email isset';
}
if (isset($_POST['gender'])) {
echo 'gender isset';
}
我不明白的是:即使我将字段留空,它也会输出来自 name 和 email 循环的 2 个回声,而不是 gender 循环。
有人可以解释为什么即使我将字段留空并提交,名称和电子邮件的返回值也是 TRUE 吗?
为什么,如果我不点击任何收音机,这个返回值是 FALSE? (echo 'gender isset'; 没有输出!)
【问题讨论】:
-
空字段仅表示
""空输入字符串,而不是它们的缺失。