java - create form in head of main view template -
i have view template contains head, menu, footer (i phone call file main template). template called other pages have content. decided add together form login menu. first thought pass form view file rendered via controller main template parameter don't need show login form everytime on every page would't solution.
i have 2 solution in both have problem:
i created form in main template helper form , input , button 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 handle in controller dynamicform , want transfor form represent model 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) blank , don't understand why.
i wanted create form in main template model representation can't write code compile (it has problem logform know wrong yet tried lots of combination 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 utilize dynamicform
binding filling form<user_login>
can @ 1 time (and that's solution you):
public static result loginapproach(){ form<user_login> loginform = form(user_login.class).bindfromrequest(); string formtostring = loginform.get().email + " pass: " + loginform.get().passwd; homecoming ok(formtostring); }
java playframework-2.1
No comments:
Post a Comment