cakephp

Saving a Disabled field


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.


Solution

  • 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 (since, its not needed as user don’t need to change it).