default element value in Form Builder

Hello all ,

Is there any way to create an element with default/initial value ?

for example ( that not works ) :




        'value' => '999',

         ) ,



You can set it from your controller, like this


where $form is a CForm object,

or you can set default values inside your rules function.

Thank you . Funny . i didn’t think about that …

sumwai, et al, I’m trying to get my form builder form to display default values, and I’d like to keep this type of thing out of the controller. However, when I try to set default values in my rules, they don’t appear in my form (!). Your method of encoding at the controller level works fine, though.

Is there some way that form builder is not relating to the model in the usual way? I ask this because I have some beforeValidate() code in my model, which is not getting executed before validation either.

Or is there something I’m missing…?

Found the answer to my question. The validation rules only activate upon validation — meaning they don’t execute before displaying a form :



Actually you can still do this on the view as follows:


<?php echo $form->hiddenField/TextField($model,‘requestor’,array(‘value’=>$requestor)); ?>