首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP验证-检查是否填充了3个字段中的一个

PHP验证-检查是否填充了3个字段中的一个
EN

Stack Overflow用户
提问于 2015-11-20 01:06:37
回答 4查看 65关注 0票数 0

我试图验证三个相关的字段。这3个字段的形式已经有几十个字段,其中许多字段正在验证。

对于所讨论的3个相关字段,我需要编写代码,检查其中的一个字段是否已填充,如果其他两个字段中的任何一个未填充,则抛出一个错误。

  • 因此,如果A被填充,而B和C不是= error。
  • 如果B被填充,而A和C不= error。
  • 如果填充了C,而A和B不= error。 然后再加上两个和第三个,没有。

例如:如果A和B被填充,而C不是= error。

这里是我开始的地方,但不确定这是否正确的验证:

代码语言:javascript
运行
复制
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';

}
EN

Stack Overflow用户

发布于 2015-11-20 01:19:53

没有对此进行测试,但是尝试一下:

代码语言:javascript
运行
复制
<?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
}
票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33817294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档