I have html to post back a form, like this:
@(message: String)
@main("Contact") {
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/contact.css")">
<div id="pageContainer">
<div id="form">
<div id="topText">
<p>Have a question or need some assistance? Let us know and we'll get back to you ASAP.</p>
</div>
<br/>
<form method="POST" action="@routes.Home.contact()">
<div id="contactInfo">
<label class="contactLabel">First Name:</label><input type="text" name="firstName" id="firstName" class="contactInput" /> <br />
<label class="contactLabel">Last Name:</label><input type="text" name="lastName" id="lastName" class="contactInput" /> <br />
<label class="contactLabel">Email:</label><input type="text" name="email" id="email" firstName" class="contactInput" /> <br />
<label class="contactLabel">Company:</label><input type="text" id="company" name="company" class="contactInput" /> <br />
<input type="hidden" id="hidden" name = "hidden"></input>
<p id="crap">@message</p>
</div>
<br/>
<div id="message">
<label class="contactLabel">Message:</label><textarea cols="50" rows="10"></textarea>
</div>
<input type="submit" name="submit" id="submit" value="Submit"></input>
</form>
</div>
</div>
}
Back in the controller, it looks like this:
public static Result contact()
{
//Map<String,String[]> values = request().body();
DynamicForm form = form().bindFromRequest();
String first = "";
if(form.data().get("firstName") != null)
first = form.data().get("firstName").toString();
return ok(views.html.contact.render(first));
}
But when I look through the result of form().bindFromRequest()
, it is always empty. Am I missing something?
String hello, String hello1, String hello2
to yourHome.contact
method instead of retrieving them withbindFromRequest
? – HareldafirstName
both in controller and view? – Hareldahello
. Please show the real one, and the code of theHome.contact
method including definition. – Harelda