ActiveForm checkbox (checked?)


How can I get a checked checkbox by default using ActiveForm??

<?php $form=$this->beginWidget('CActiveForm', array(



    'clientOptions' => array(



)); ?>


<?php echo $form->checkBox($model,'estado'); ?>

something like this

<input type="checkbox" name="option" value="estado" checked /> 


Use your htmlOptions parameter - array(‘checked’=>‘checked’);

<?php echo $form->checkBox($model,'estado',  array('checked'=>'checked')); ?>

Won’t that make the checkBox ALWAYS checked?

I have used:

	<div class="row">

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

		<?php echo $form->checkBox($model,'is_host'); ?>

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


before and it worked in create and update.

If OP is trying to set a default value for a new record then try:


   public function actionCreate()


      $model=new Podcasts;





         if($model->save()) {



         } //EndIf($model->save())


      $this->is_host = true;          //<-- Add this





It works! Thnx ;)