我有以下代码检查是否所有变量都已设置,只有当所有参数都设置为isset()
时才会返回trueif (isset($_POST['FirstName'], $_POST['Surname'],
$_POST['Telephone'], $_POST['email'], $_POST['PickupPoint'],
$_POST['Destination'], $_POST['StartDate'],
$_POST['NumberofPassengers'])) {
"if all fields have a POST value then send email"
else{
echo "Please fill in all fields.";
}
然而,即使例如PickupPoint和Destination未填写,电子邮件也会被发送。
答案 0 :(得分:3)
这里的问题是空白字段仍然计为设置。你还需要检查它是否为空$_POST['PickupPoint'] !== ''
完整示例:
if (isset($_POST['FirstName'], $_POST['Surname'],
$_POST['Telephone'], $_POST['email'], $_POST['PickupPoint'],
$_POST['Destination'], $_POST['StartDate'],
$_POST['NumberofPassengers']) && $_POST['PickupPoint'] !== '' && $_POST['Destination'] !== '') { ...
虽然我建议检查所有字段