2013-05-17 58 views
0

我目前正在使用Play框架,但似乎没有什么关于表单的信息。玩框架和表格

在我得到的东西,看起来像这样的时刻: 的路线是:

GET /test controllers.Application.testMethod() 

的方法:

public static Result testMethod(){ 
    //handles the Form 
} 

的NameResidencePair类:

public static class NameResidencePair{ 
    public String name; 
    public String residence; 
} 

斯卡拉.html以表格形式提供的网页

@(aForm: Form[NameResidencePair]) 

@import helper._ 
@form(action = routes.Application.testMethod) { 

@inputText(
field = userForm("name") 
) 

@inputText(
field = userForm("residence") 
) 
} 

如果我仍然想要一个表单,但是其中一个值(如居住地)始终是相同的值,该怎么办?例如:residence =“在云上”。我仍然想通过表单传递它,但我不想要一个文本框。换句话说,我想通过一个名称和居住形式,但只有名称应该是可编辑的,并在输入字段中可见。

回答

2

显而易见的解决方案是一个隐藏的表单字段:

<input type="hidden" name="residence" value="On a cloud"> 

There is no form template helper创建一个隐藏的领域,但粘贴该行到你的代码不应该太多的工作。 :-)

但请不要只因为它被隐藏,你不能认为这个值永远是“在云上”。这仅仅意味着“表单字段是隐藏的”,用户仍然可以发送任意值。所以请仍然检查用户输入。