2

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.

RavatSinh Sisodiya
  • 1,596
  • 1
  • 20
  • 42
alexkd
  • 203
  • 1
  • 4
  • 13

2 Answers2

4

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'));

Saanch
  • 1,814
  • 1
  • 24
  • 38
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)

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • echo this->Form->input('patient_id',array('type'=>'hidden')); echo $this->Form->input('patient_id',array('disabled'=>'true'));When I code like above this also not posting patient_id. – alexkd May 02 '12 at 04:42
  • If you use hidden fields, users can still easily edit them! Make sure you use some sort of form tampering protection to prevent this (see: SecurityComponent). – jeremyharris May 02 '12 at 14:49
  • But when making the field readonly. All options in the select box still changeable to the user. How to make it solve?. – alexkd May 03 '12 at 03:14