Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play html form to submit a GET request with parameter

I have a play GET route, 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-m-v-t">
            <input type="submit" data-icon='&#xe6660;' class="btn btn-primary btn-large" value="Sign Up">
       </div>
}

It gives me an error:

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

like image 498
angelokh Avatar asked Feb 03 '13 23:02

angelokh


1 Answers

You don't need to pass it twice (via route argument and form's hidden field) so you have two solutions: use only route arg:

Route's argument

route

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

template

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

of course if you have only this one field you can use link directly:

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

java action

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

Form field only

remove argument from the route and bind field from request in controller:

route

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"));
}
like image 197
biesior Avatar answered Oct 03 '22 04:10

biesior