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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料