我在获取表单中的复选框然后传递给 .php 文件时遇到了很多麻烦。 html 看起来像
<td><label for="services">Services Requested:</label></td>
<td><form name="services" action="processForm.php" method="post">
<input type="checkbox" name="services[]" value="Massage" />Massage
<input type="checkbox" name="services[]" value="Facial" />Facial
<input type="checkbox" name="services[]" value="Manicure" />Manicure
<input type="checkbox" name="services[]" value="Pedicure" />Pedicure
</form>
</td></tr>
我立即在 processForm.php 中设置 $services = $_POST['services'];
。
但是这个存在于 processForm.php 中的错误每次仍然会出现。
if(empty($services)) {
$errors[] = "You must choose at least one service.";
}
最佳答案
尝试更改复选框的名称。它们与表单同名
关于php - 复选框数组 html php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15175246/