dongxieyou3314 2012-12-25 23:56
浏览 83
已采纳

Php - 表单验证 - 下拉菜单+评论框

I have been working on a input form for students for the past couple of hours. I have done mostly all of it with 0 hicups but I come across one minor issue that I can't think of a work around for. I have a drop down menu and the validation for that is :

 }
        if(empty($why) === true) {
            $errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
    }

the default variable is set to be empty or just value="" (empty)...

now the next thing I need to validate is that if the student chooses the option "Other" I need them to then insert at least 10 characters and max of 30 into a Comments box specifically made for the students who can not find the general reason for their visit to the financial aid office. This is what I have for this (it is not working btw) :

if(isset($why) === Other) {
        $errors[] = 'Please add a comment explaining why you are visiting the office.';
}

So all in all I need help writing a validation that if the student chooses other then he or she MUST then write a brief summary as to why he or she is visiting the office in the "comments box".

Any help would be lovely. Thank you.

  • 写回答

2条回答 默认 最新

  • dongzhuo3059 2012-12-26 00:10
    关注

    Lets say that the textarea for the 'other' field is called $other

    if(empty($why)){
      $errors[] = 'Please select a reason';
    }elseif($why == 'Other' && empty($other)){
      $errors[] = 'You selected Other. Please enter a reason why';
    }
    

    Your code will probably need to be more detailed than the above since you're looking to set a minimum and maximum number of characters, but you get the jist?

    BTW, I see no reason why you would want to use the === operator instead of the == operator. They do the exact same thing but === checks to see if it's the same type, not sure what good this does for your script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来