gerhard
(gerhard@ecolar.co.za)
February 29, 2012, 10:42pm
1
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?
rich_c
(Richc)
February 29, 2012, 10:58pm
2
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.
gerhard
(gerhard@ecolar.co.za)
March 1, 2012, 6:48am
3
Hi Rich C
This is my actual code:
<div class="form">
<?php $this->renderPartial('_form', array('form'=>$form)); ?>
<?php echo $form['user']; ?>
<?php echo $form['profile']; ?>
<?php echo $form['subformbuttons']; ?>
</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
gerhard
(gerhard@ecolar.co.za)
March 2, 2012, 2:13pm
4
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.
lalzada
(Lalzadamohmand)
March 5, 2013, 7:09am
5
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]