2017-04-12 107 views
0

我有一个奇怪的问题,我无法解释。我使用播放框架,当我尝试运行下面的视图时,它只适用于当我重复下面的表单动作...它的作品,但我知道这是不正确的。如果有人能帮助解释或纠正,我们会很感激。斯卡拉玩形式

@(errorMessage: String = "")(implicit messages: Messages) 

@helper.form(routes.ApplicationHomeController.login) { 
    @main(title = messages("single.title")) { 
     <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css"> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
     <div id="userbox"> 
      <form action="@{routes.ApplicationController.doLogin()}" method="post"></form> 

      <form action="@{routes.ApplicationController.doLogin()}" method="post"> 
       <div style="color: red">@errorMessage</div> 
       <h1 id="logintxt" style="background-color: rgb(11, 146, 9); 
          background-position: initial; 
          background-repeat: initial;">Driver Service <b>ß</b>eta</h1> 

       <div id="submit_giff" style="display: none;"> 
        <hi> Authenticating: <img src="/assets/images/loader-bar.gif" align="absmiddle"> </hi> 
       </div> 
       <input id="name" name="userName" placeholder="Username" style="opacity: 1; 
          background-color: rgb(255, 255, 255); 
          background-position: initial; 
          background-repeat: initial;"> 
       <input id="pass" name="password" type="password" placeholder="Password" style="opacity: 1; 
          background-color: rgb(255, 255, 255); 
          background-position: initial; 
          background-repeat: initial;"> 

       <p id="namealert" style="display: none; 
          opacity: 1;">Username:</p> 
       <p id="passal" style="display: none; 
          opacity: 1;">Password:</p> 
       <input id="loginbtn" style="opacity: 0.2; 
          cursor: default;" type="submit" value="Login"> 
      </form> 
     </div> 
     <script src="/assets/javascripts/login.js"></script> 
    } 
} 

回答

2

两个直接的意见。

其中:@helper.form(...)会将<form>元素写入最终生成的HTML中。您的观点则包含其他文字<form>的嵌套里面的第一种形式。 Nested forms are invalid HTML。您有一份表格提交至routes.ApplicationController.doLogin,另一份提交至routes.ApplicationController.login。谁知道浏览器实际提交哪些内容?我们无法真正预测,因为嵌套表单无效。

二:你有你的@main(...)视图嵌套里面你的@helper.form(...)。我假设你的主视图包含<html>...</html>。这将导致HTML开始于<form>元素,内部这是<html>元素。这也是非常无效的标记。

我的猜测是这些问题中的一个或两个都是你的问题。

尝试将生成的HTML文件通过HTML验证程序(如https://validator.nu/)运行。修复验证程序发现的任何问题,不要嵌套表单,并决定登录表单应实际提交的路径(单一)。