我试图验证三个相关的字段。这3个字段的形式已经有几十个字段,其中许多字段正在验证。
对于所讨论的3个相关字段,我需要编写代码,检查其中的一个字段是否已填充,如果其他两个字段中的任何一个未填充,则抛出一个错误。
例如:如果A和B被填充,而C不是= error。
这里是我开始的地方,但不确定这是否正确的验证:
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';
}发布于 2015-11-20 01:19:53
没有对此进行测试,但是尝试一下:
<?php
if(empty(array(
$_post['email_notify_subject'],
$_post['email_notify_date'],
$_post['email_notify_emails']))){
echo "All Three filed required"; //or other instructions
}
else{
//Proceed with the form
}https://stackoverflow.com/questions/33817294
复制相似问题