问题
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 likeecho $this->Form->input('patient_id',array('type'=>'select', 'readonly' => 'readonly'));
来源:https://stackoverflow.com/questions/10407758/saving-a-disabled-field