Nested CActiveForm not working

I have the following code in my main index.php:


<div class="form">

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

'id' => 'test-form',

'enableAjaxValidation' => false,

'enableClientValidation' => true,

'clientOptions' => array(

    'validateOnSubmit' => true,

),

'focus' => array($oTest, 'title'),

)); ?>


<fieldset>

    <legend>Questions</legend>

    <div id="questions">

        <?php echo $oForm->hiddenField($oTest, '_id');  ?>

        <?php $this->renderPartial('_showQuestions', array('oTest' => $oTest)); ?>

    </div>

</fieldset>


<fieldset>

    <legend>Reviewers</legend>

    <div class="row">

        <?php echo $oForm->labelEx($oTest, 'reviewers'); ?>

        <?php echo $oForm->textField($oTest, 'reviewers', array('size' => 140)); ?>

    </div>

</fieldset>

<fieldset>

//stuff

</fieldset>

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

and the following code in the partial view _showQuestions


<div class="form">

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

'id' => 'question-form2',

'enableAjaxValidation' => false,

'enableClientValidation' => true,

'clientOptions' => array(

    'validateOnSubmit' => true,

),

)); ?>

<?php echo $oForm->hiddenField($oTest, '_id'); ?>


<?php

foreach ($oTest->questions as $oQuestion)

{

    var_dump($oQuestion);

}

?>





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

The problem is that, if I run this, the firebug result of the total form is this:

2617

WhatItIs.jpg

But I would like it to be like this:

2618

WhatIWant.jpg

Any clues about what I might be doing wrong?

have you tried without the renderPartial() to see if it works as expected. Are you sure that the model returns all records that you are expecting?

without the renderpartial everything works as expected. As soon as I remove the CActiveFrom within the renderpartial everything also works as it should

I don’t think the nested forms work properly.

Try passing the form object created in the main form to the 2nd form(fragment) instead …




// in main form

...

        <?php $this->renderPartial('_showQuestions', array('oTest' => $oTest, 'form' => $form)); ?>

...

// in sub form fragment

// without calling "beginWidget('CActiveForm', ...), use the main form object

<?php echo $form->hiddenField($oTest, '_id'); ?>

...