dongpu1331 2017-02-07 16:32
浏览 74
已采纳

在此上下文中元素选择中不允许使用文本

I created a forum, where students have to fill out their year of graduation. When I was validating my file, as shown by the comment, the line below produces an error, "Text not allowed in element select in this context." I need to name "year" in the select tag, so I can use the post array to get the year. How can I fix this validation error?

<form method="post">
    <div class = "mailInput"> 
        Name: <input type="text" name="name"> 
            <span class="error"> <?php echo $nameErr;?></span></div>
    <div class = "mailInput">
        Email: <input type="text" name="email"> 
            <span class="error"> <?php echo $emailErr;?></span> </div>
    <div class = "mailInput">
        Major: <input type="text" name="major"> 
            <span class="error"> <?php echo $majorErr;?></span> </div>
    <div class = "mailInput">
        Year: <select class="select" name="year"> // this line produces an error
            <option value="2017">2017</option>
            <option value="2018">2018</option>
            <option value="2019">2019</option>
            <option value="2020">2020</option>
        </select> 
    </div>
    <div class = "mailInput lastInput"> Gender:  
         <input type="radio" name="gender" value="Female">Female
         <input type="radio" name="gender" value="Male">Male
    </div>
    <span class="error"> <?php echo $genderErr;?></span>
    <div class = "submitButton"><input type="submit" name="submit" value="Join">
    </div>
    <div class="message"> <?php echo $submitMessage;?></div>
</form>
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
    if (!empty($_POST["year"])) {
        $year = $_POST["year"];
    }
}
  • 写回答

1条回答 默认 最新

  • douya2007 2017-02-07 16:42
    关注

    // this line produces an error will prevent your code from working as it is not the correct way to write comments in HTML code.

    The correct way is by using <!-- --> and therefore, in your case, it should have been <!-- this line produces an error -->

    // is used to write comments in PHP and JavaScript.

    /* */ is used to write comments in CSS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?