Here I go again with my newbie help requests. I need to submit a form after it’s shown in a modal dialog. The catch is, the form refers to a different model from the view that renders it. Let’s say I’m watching a list of classrooms and I want to show a dialog to insert a new student to one of them.
In my view (say classroom/index.php) I have this code for rendering the dialog button
$this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'myModal')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Add a Student</h4>
</div>
<div class="modal-body">
<p><?php $this->renderPartial('_myForm',array(),false)?></p>
</div>
<?php $this->endWidget(); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Click me',
'type' => 'primary',
'htmlOptions' => array(
'data-toggle' => 'modal',
'data-target' => '#myModal',
),
)
);
And the _myForm view file is
<div class="form">
<?php
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');
$model = new Student(); //this is my model
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
'id' => 'student-form',
'enableAjaxValidation' => true,
'enableClientValidation'=> false,
)); ?>
<p class="note">
<?php echo Yii::t('AweCrud.app', 'Fields with') ?> <span class="required">*</span>
<?php echo Yii::t('AweCrud.app', 'are required') ?>. </p>
<?php echo $form->errorSummary($model) ?>
<?php //form fields here.. ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'label'=> Yii::t('AweCrud.app', 'Cancel'),
//'htmlOptions' => array('onclick' => 'javascript:history.go(-1)')
)); ?>
</div>
<?php $this->endWidget(); ?>
</div>
I’m not sure how I should code my controller. Atm after submit nothing happens: and I’m not very surprised since there’s no specific action invoked. But I’m confused… Should I use the StudentController? Or the ClassroomController? And how?