我想验证3个相关的字段。这3个字段的格式已经有几十个字段,其中许多字段正在验证中。PHP验证 - 检查是否有1个字段填充
对于所讨论的3个相关领域,我需要编写,检查是否任何3的1被填充的代码,然后将引发一个错误,如果任何其他的2都没有。
- 所以如果A被填充而B和C不是=错误。
- 如果B填充并且A和C不是=错误。
如果C被填充并且A和B不是=错误。
再等两个被填充;第三,没有。
喜欢:如果A和B填充和C不是=错误。
这里是我起步的地方,但不知道这是正确的验证:
if(!empty($post['email_notify_subject'])
&& empty($post['email_notify_date'])
&& empty($post['email_notify_emails']))
{
$errors['email_notify_date'] = 'Enter Notify Date';
$errors['email_notify_emails'] = 'Enter Notify Emails';
}
else if (empty($post['email_notify_subject'])
&& !empty($post['email_notify_date'])
&& empty($post['email_notify_emails']))
{
$errors['email_notify_subject'] = 'Enter Notify Subject';
$errors['email_notify_emails'] = 'Enter Notify Emails';
}
else if (empty($post['email_notify_subject'])
&& empty($post['email_notify_date'])
&& !empty($post['email_notify_emails']))
{
$errors['email_notify_subject'] = 'Enter Notify Subject';
$errors['email_notify_date'] = 'Enter Notify Date';
}
我们需要更多的代码比一行... – Machavity
后这些字段的HTML代码,以及你的
有什么好运气? –