简体   繁体   English

游戏框架形式

[英]Playframework forms

I'm creating a form to allow users to edit my objects, but it seems that only the object fields that are editable in the form are available within my controller once the form is submitted. 我正在创建一个允许用户编辑我的对象的表单,但是似乎一旦提交表单,控制器中就只有在表单中可编辑的对象字段可用。 My example is a user object that I present in a form to allow the user to edit the name field, when they submit the form my controller needs to determine if this is a new user or an exiting user. 我的示例是一个用户对象,我在表单中显示该对象以允许用户编辑名称字段,当他们提交表单时,控制器需要确定这是新用户还是退出用户。 To determine this I check the ID field, but since the ID field is not editable on the form it is null, when I check it in the controller. 为了确定这一点,我检查了ID字段,但是由于ID字段在表单上不可编辑,因此当我在控制器中对其进行检查时,该字段为null。

Have I missed something? 我错过了什么吗?

For this scenario, keep your id has hidden input in template. 对于这种情况,请确保您的ID在模板中具有隐藏的输入。 So that it will be available for you in controller after user hitting form's submit button. 这样,当用户点击表单的“提交”按钮后,它将在控制器中对您可用。

<input type="hidden" name="id" value='@userForm.field("id").value' >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM