want to disable field but need to store value

i need to disable my field but i want to store its default value.

i stored default value in it and made it disable but when i create a record it showing error ‘field is required’ and when i remove its validation it stores 0 all time.

thanx in advance…

If you are talking about form fields: a disabled field is not sent with the POST data (if I remember correctly).

Possible fixes, any of:

-Make it hidden or read only.

-Add a ‘default’ rule to the model for that attribute.

-Initialise the value in init()

the easiest way I can think of just use a hidden field and set a default value like so


<?php echo $form->hiddenField($model, 'fieldName', array('value'=>'abcd')); ?>

otherwise look at the following thread

http://www.yiiframework.com/forum/index.php/topic/11960-preferred-way-to-set-dynamic-default-values-in-a-cactiverecord-model/

thank you all of you…

i used readonly instead of disable, now its working…