Readonly Field in CActiveForm


I can’t figure out how to make a field Readonly in my CActiveForm. Here is what I tried:

<?php echo $form->textField($model,'email',array('readonly'=>true)); ?>

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

<?php echo $form->textField($model,'email',array('htmloptions'=>array('readonly'=>true))); ?>

<?php echo $form->textField($model,'email',array('htmloptions'=>array('readonly'=>'readonly'))); ?>

I also tried in the Model to add the validation rule:

array('email', 'contraints', 'readOnly'=>true, 'on'=>'update'),

But nothing seems to work, any idea?


The first form seems to be ok, you can try

<?php echo CHtml::textField("email",$model->email,array('readonly'=>true)); ?>

Indeed the first one was working and your solution is also working… The problem was from elsewhere, I was just not looking at the right place! Can’t believe it took me an entire day to realize that…

Sorry for the time and thanks a lot!