[SOLVED]. Yii Model Optional Form Fields

I have a table for users with regular fields username, password and isactive (with default value set to false).

I created a model for this table and a form from the same. The form is created with the isactive field shown in the form.I dont want the isactive field to be shown in the form. I dont want the value of this field to be changed by user when he registers, only the admin can change the value of this field. How do i disabled the field from being rendered in the form ??

You can add htmlOptions attributes like this :

<?php echo $form->textField($model,'isactive',array('style'=>'display:none')); ?>

with display:none the field is not visible on the screen but is visible in the HTML source and some malicious user could use some tricks to post that value…

you can just test in your code if the current user is an admin and if it’s not do not render the field at all…

something like



   echo $form->textfield(....

   echo ...


Solved. Just deleted the particular field from the form php file. Made some changes to the controller action where the form gets submited i.e. manually set the value for that particular field after the form validation completest successfully.