0

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>
<?php $this->endWidget(); ?>

and the following code in the partial view _showSuestions

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

Now the problem is that this doesn't work. When I fisit my page, the form tag is suddenly closed after I called my partialView. i'm guessing this is because of the nested CActiveForm? When I remove the inner CActiveForm it works

tereško
  • 58,060
  • 25
  • 98
  • 150
SnIpY
  • 662
  • 2
  • 10
  • 27
  • i think you need a $oForm->endWidget() in the first file – Mukesh Soni Mar 01 '12 at 16:00
  • Woeps, forgot to copy paste it, but it was there, has nothing to do with the error – SnIpY Mar 01 '12 at 16:07
  • Nothing... The functionality is just off. When i look in firebug, I see the main form is closed when I close the inner form.. That shouldn't happen – SnIpY Mar 01 '12 at 16:46
  • [You cannot nest HTML forms](http://stackoverflow.com/questions/379610/can-you-nest-html-forms). – DCoder Jul 08 '12 at 04:43

1 Answers1

1

try changing the name of the second form variable (in _showQuestions file), say, oForm to tForm. there is a variable name clash. Because at the end of the day, renderPartial is nothing but a include.

Mukesh Soni
  • 6,646
  • 3
  • 30
  • 37
  • Also doesn't work... I think it is probably complaining because I have a form in a form? – SnIpY Mar 01 '12 at 18:02
  • can't be... the start and end tags take care of the defining your forms clearly.. just curious, why are you using the hidden field, _id of oTest, twice? yii might be creating two from elements with same id (html element one) and the browser might be spooked by that. – Mukesh Soni Mar 01 '12 at 18:09