Reputation: 2935
I'm a bit confused how I can create a submit button with parameter in play framework 2. I try this:
<form method="GET">
<table class="table table-bordered table-hover">
<tr>
<th>@Messages("id")</th>
<th>@Messages("errorCode")</th>
<th>@Messages("errorMessage")</th>
</tr>
@for(telegram <- telegrams) {
<tr>
<td>@telegram.id</td>
<td>@telegram.errorCode</td>
<td>@telegram.errorMessage</td>
<td><button type="submit" name="action" value="@controllers.routes.Telegrams.createTelegram(telegram.id)">Create Telegram</button></td>
</tr>
}
</table>
</form>
In the routes file I add this line:
GET /telegrams/createTelegram/:id controllers.Telegrams.createTelegram(id: Long)
Nothing happens. No error. No controller call.
I don't know what's wrong.
Any idea? Thanks in advance!
Upvotes: 0
Views: 1144
Reputation: 443
Why does it have to be a form with a button for a simple HTTP GET
? A link will do the same job:
@for(telegram <- telegrams) {
<tr>
<td>@telegram.id</td>
<td>@telegram.errorCode</td>
<td>@telegram.errorMessage</td>
<td><a href="@controllers.routes.Telegrams.createTelegram(telegram.id)">Create telegram</a></td>
</tr>
}
Upvotes: 1
Reputation: 55798
The URL should go to the action
attribute of the form
element (separate form
for each loop iteration):
@for(telegram <- telegrams) {
<form method="GET" action="@controllers.routes.Telegrams.createTelegram(telegram.id)">
<tr>
<td>@telegram.id</td>
<td>@telegram.errorCode</td>
<td>@telegram.errorMessage</td>
<td><input type="submit" value="Create telegram" /></td>
</tr>
</form>
}
Upvotes: 1