Nested Forms

Hi

I have worked through Nested Forms in the Definitive Yii guide1.1.8.

I made three subforms: user, profile and subformbutton.

Subformbutton only contains a button and looks as follows:

           'subformbutton'=>array(


		'type'=>'form',


		'elements'=>array(''


		),


		'buttons'=>array(


			'register'=>array(


				'type'=>'submit',


				'label'=>'register',


			),


		),


	),

If I render the form like on page 72, then all three subforms work fine and subformbutton’s button submits the form as it should:

<h1>Register</h1>

<div class="form">

<?php echo $form; ?>

</div>

But when I render the subforms individually – like on page 73, the button of subformbutton stops submitting the form:

some complex UI elements here

<?php echo $form[‘user’]; ?>

some complex UI elements here

<?php echo $form[‘profile’]; ?>

some complex UI elements here

<?php echo $form['subformbutton]; ?>

(Note the typos in the guide: username i.s.o. user; password i.s.o. profile)

Any ideas, thanx?

I assume your missing quote in <?php echo $form['subformbutton]; ?> is a transcription error?

Also, check the source code and make sure there is only one <form> tag being generated, and that the button is inside it.

Hi Rich C

This is my actual code:

<div class="form">

&lt;?php &#036;this-&gt;renderPartial('_form', array('form'=&gt;&#036;form)); ?&gt;


&lt;?php echo &#036;form['user']; ?&gt;


&lt;?php echo &#036;form['profile']; ?&gt;


&lt;?php echo &#036;form['subformbuttons']; ?&gt;

</div>

As you can see I first display the whole form in one line, and then the three individual subforms.

What is more - if I take out the rendering of the whole form (the renderPartial line) and only leave the individual echo lines (like the example in the guide page 73), then I get the following error:

Fatal error: Call to a member function error() on a non-object in C:\xampp\htdocs\Yii\framework\web\form\CFormInputElement.php on line 232

I found the answer.

The displaying of the individual subforms should be preceded by "echo $form->renderBegin()" and followed by "echo $form->renderEnd()".

It might be something to include in the example on page 73. Just a thought, could save the next guy two days.

for individual form elements you must have renderBegin() and renderEnd()

[indent]echo $form->renderBegin();

echo $form[‘user’];

echo $form[‘profile’];

echo $form->buttons[‘register’];

echo $form->renderEnd(); [/indent]