Saving a Disabled field

时光总嘲笑我的痴心妄想 提交于 2021-02-10 05:14:51

问题


In my edit.ctp I have a select box which I don't need the user to change. So I put array(disabled=>true). But this field is not coming when

pr($this->data); and showing an error while saving.

What options are there to solve this issue.


回答1:


You could make the field readonly so that user cant change it , or use some hidden field to post the data that you want, or you could use some css, like visibility:hidden, so that user dont see it but it'll be posted.

echo this->Form->input('patient_id',array('type'=>'hidden'));   

You can use some other name for the input and check in controller, or you could completely remove the select element from the view*strong text* (since, its not needed as user dont need to change it)




回答2:


If you know the value of the data you can edit it at the controller.

$this->request->data['ModelName']['fieldName'] = value;

UPDATE

Edit it like
echo $this->Form->input('patient_id',array('type'=>'select', 'readonly' => 'readonly'));



来源:https://stackoverflow.com/questions/10407758/saving-a-disabled-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!