I have a view template which contains head, menu, footer (I will call this file as main template). This template is called by other pages which have some content. I decided to add form for login into menu. My first idea was about pass form from view file which is rendered via controller into main template by parameter but I don’t need show login form everytime on every page so this would’t be my solution.
I have two solution but in both I have a problem:
-
I created form in main template with helper for form and input and button with pure html
@helper.form(routes.Application.loginPosted,'class -> "navbar-form pull-right"){ <input class="span2" type="text" placeholder="email" name="email"> <input class="span2" type="password" placeholder="passwd" name="passwd"> <button type="submit" class="btn btn-primary">Login</button> }and I handle it in controller as DynamicForm and want it transfor into form which represent a model for easier validation
DynamicForm requestData = form().bindFromRequest(); Form<User_Login> loginFormFilled = form(User_Login.class); loginFormFilled.fill(new User_Login(requestData.get("email"), requestData.get("passwd")));but loginFormFilled.get().email (and passwd too) is always blank and I don’t understand why.
-
I wanted create form in main template as a model representation but I can’t write code which will be compile (it has problem with logForm I know that it is incorrect but I yet tried lots of combination but I can’t create valid form)
@val logForm = new Form[User_Login] @helper.form(routes.Application.loginPosted,'class -> "navbar-form pull-right"){ @helper.inputText( logForm("email") ) @helper.inputPassword( logForm("passwd") ) <button type="submit" class="btn btn-primary">Login</button> }
You don’t need to use
DynamicFormbinding for filling theForm<User_Login>you can do that at once (and probably that’s solution for you):