我想驗證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代碼,以及你的
有什麼好運氣? –