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!