ActiveForm checkbox (checked?)

Hi!

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


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

	'id'=>'lectivo-form',

	'enableAjaxValidation'=>true,

    'clientOptions' => array(

      'validateOnSubmit'=>true

   ),

)); ?>


...


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



something like this




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



regards

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'); ?>

	</div>



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(isset($_POST['Podcasts']))

      {

         $model->attributes=$_POST['Podcasts'];

			

         if($model->save()) {

            ...

            $this->redirect(array('view','id'=>$model->ID));

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

      }


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

      $this->render('create',array(

			'model'=>$model,

		));

	}



It works! Thnx ;)