Play html form to send a GET request with parameter

I have a GET route for the game, how can I use it in scala html form?

routes

GET /service/register controllers.WebRegister.register(plan?="") 

scala html

 @form(action = routes.WebRegister.register, 'style -> "width: 320px;") { <fieldset> <input type="hidden" name="plan" value="FREE" id="plan"> </fieldset> <div class="form-actions plan-form peer-btn-center peer-mvt"> <input type="submit" data-icon='&#xe6660;' class="btn btn-primary btn-large" value="Sign Up"> </div> } 

This gives me an error:

missing arguments for the method register in the ReverseWebRegister class; [error] follow this method with `_ 'if you want to treat it as a partially applied function

+4
source share
1 answer

You do not need to pass it twice (via the route argument and the hidden form field), so you have two solutions: use only route arg:

Route argument

way

 GET /service/register controllers.WebRegister.register(plan: String?="") 

template

 @form(action = routes.WebRegister.register("free")) { <input type="submit"> } 

Of course, if you have only one field, you can directly use the link:

 <a href='@routes.WebRegister.register("free")'>Register free</a> 

java action

 public static Result register(String plan) { return ok(plan); } 

Form field only

remove the argument from the route and associate the field with the request in the controller:

way

 GET /service/register controllers.WebRegister.register 

template

 @form(action = routes.WebRegister.register) { <input type="hidden" name="plan" value="free"> <input type="submit"> } 

java action

 public static Result register() { return ok(form().bindFromRequest().get("plan")); } 
+5
source

All Articles