CHtml vs CForm for a CActiveForm

I’d like to create a CActiveForm using the CForm system.

What I don’t understand is why building the form using CHtml in the view file like this works:


<div class="form">

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

    'id'=>'answer-form',

    'enableAjaxValidation'=>true,

)); ?>


<?php echo $form->errorSummary($model); ?>


<div class="row">

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

    <?php echo $form->textArea($model,'content'); ?>

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

</div>


<?php echo CHtml::submitButton('Answer'); ?>


<?php $this->endWidget(); ?>

</div>

While the following CForm combined with the view code below does not work:


<?php

return array(

    'title'=>yii::t('main','Please enter your answer'),


    'activeForm' => array(

        'class' => 'CActiveForm',

        'enableAjaxValidation' => true,

        'id' => 'answer-form',

        'clientOptions'=>array(

            'validateOnSubmit'=>true,

            'validateOnChange'=>false,

            'validateOnType'=>false,

        ),

    ),


    'elements'=>array(

        'content'=>array(

            'type'=>'textarea',

        ),

    ),


    'buttons'=>array(

        'submit'=>array(

            'type'=>'submit',

            'label'=>yii::t('core','Submit'),

        ),

    ),

);



view file:


<div class="form">

    <?php echo $form; ?>

</div>

the content element is set to be required in the rules section of the model.

I swear I had it working yesterday, but can’t seem to figure it out today and it’s really frustrating. Can anybody explain to me what I’m doing wrong in building a CActiveForm using CForm?!?

Thanks!

I’ve sloved half the issue:

Both work, but the CForm-approach doesn’t work with the CWebLogRoute part of my logging configuration enabled:




        'log'=>array(

            'class'=>'CLogRouter',

            'routes'=>array(

                array(

                    'class'=>'CWebLogRoute',

                    'levels'=>'trace, info, error, warning',

                    'filter'=>'CLogFilter',

                    'categories'=>'system.db.CDbCommand',

                    'showInFireBug'=>true, // firebug only

                ),

                array(

                    'class'=>'CFileLogRoute',

                    'levels'=>'trace, info, error, warning, watch',

                    'filter'=>'CLogFilter',

                    'categories'=>'system.*',

                ),

            ),

        ),

Once I disabled the CWebLogRoute part of the log configuration the CForm-based CActiveForm JQuery scripts worked. With this enabled, it didn’t. I assume it’s due to my use of Firebug.

Is this a bug? Anybody else experience this?