disabled field


how can i disabled a certain field when update-form?

example: My form have a name, location and pasport-no field, i want to diasble passport-no when update.

Thanks for any help.

using this code will disabled a field.


but i dont know how can i do this when update-form only?

In your view code, it’s possible to build the htmlOptions conditionally and add to the field definition (e.g. dependent on model->isNewRecord).

At least something like this should work (there may be more elegant solution)

$htmlOptions = array(...);

if (!model->isNewRecord)

  $htmlOptions['disabled'] = 'disabled';

// now use $htmlOptions in the field spec.

But you can also surround the statements related to the field in question with a conditional statement (if you want to leave the field out completely).


      if ($model->isNewRecord) {









Tommy, Thank you so much for ur help. It’s works now. :D