[英]How to make CakePHP not auto-populate form values from the database?
I have a model Report
, which is related to Account
, and therefore has an account_id
field. 我有一个与
Account
相关的模型Report
,因此有一个account_id
字段。
On the Report's edit
method, I have a form with the following field: 在Report的
edit
方法中,我有一个包含以下字段的表单:
echo $this->Form->input('account_id', array(
'div' => 'accountInput',
'options' => $accounts,
'default' => $currentAccountId,
));
(NB: in this case, the 'options' doesn't need to be explictly set thanks to auto-magic) (注意:在这种情况下,由于自动魔术,'选项'不需要明确设置)
Now - the real question - if there is an existing value in the database (eg account_id == 1) then even if I include the default
as 2, value 1 still appears as selected in the html form . 现在 - 真正的问题 - 如果数据库中存在现有值(例如,account_id == 1),那么即使我将
default
值包括为2, 值1仍然在html表单中显示为已选中 。
I could use a different name for the input, but I want it to save to account_id on submission. 我可以为输入使用不同的名称,但我希望它在提交时保存到account_id。
Anyone know how to achieve this simply? 有人知道如何实现这一目标吗? (or else I add js and a hidden field or something clunky like that!)
(或者我添加js和隐藏字段或类似笨重的东西!)
Thanks, A 谢谢
您可以使用选项'value'而不是'default'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.