Cactiveform - Can You Disallow Edits Of Certain Ar Fields?

Hi folks,

I have had a thorough dig about and I can’t seem to find a way to do this…

It’s pretty simple - I have a system where an XML parser create AR classes based on parsed attributes and saves the class to the DB (providing it passes validation). So, I do not need to be able to create in the CRUD - it will be entered automatically.

Aside from the PK, there are 3 fields, two of which should not be edited manually, and a third that does require editting, and will be populated from CActiveForm::dropDownList. So, in essence, I will not have any of the fields accepting free-hand input.

The dropDownList is easy enough and is already in place (it is fed from an DB reference table). However, I want to know if there is any way to display the other 2 fields as just uneditable text i.e. like a label simply stating the DB value.

Is there any way to do this?

I tried this…

<div class="row">

<?php echo $form->labelEx($model,'field_id'); ?>

<?php echo $model->field_id; ?>

<?php echo $form->error($model,'field_id'); ?>


… and this seems to work, including AR validation. Is this an appropriate solution?

Dear Friend

We can do something like this on client side.

<?php echo $form->textField($model,'attribute',array('disabled'=>'disabled'));?>

On server side we can do some thing like this.

public function actionUpdate($id)

















I think this will provide dual protection.

I hope I helped a bit.


Agree with reply posted by seenivasan.but will add one more solution for it.Make a field as a hidden field on the form.In this way you dont want to write any code inside a controller. :)