Reputation: 283
I am currently using the Play Framework but there seems to be rather little information regarding Forms.
At the moment I got something that looks like this: The route is:
GET /test controllers.Application.testMethod()
The method:
public static Result testMethod(){
//handles the Form
}
The NameResidencePair class:
public static class NameResidencePair{
public String name;
public String residence;
}
The scala.html page featuring a form
@(aForm: Form[NameResidencePair])
@import helper._
@form(action = routes.Application.testMethod) {
@inputText(
field = userForm("name")
)
@inputText(
field = userForm("residence")
)
}
What if I still want a form but one of the values, like residence, is always the same value. Example: residence = "On a cloud". I still want to pass it via the form but I don't want a textfield. So in other words, I want to pass a form with name and residence but only the name should be editable and visible in an inputfield.
Upvotes: 0
Views: 537
Reputation: 18446
The obvious solution is a hidden form field:
<input type="hidden" name="residence" value="On a cloud">
There is no form template helper for creating a hidden field, but pasting that line into your code should not be too much work. :-)
But please not, just because it's hidden, you cannot assume that the value will always be "On a cloud". This just means "the form field is a hidden one", the user can still send an arbitrary value. So please still check the user input.
Upvotes: 2