I’m new to Yii framework and am not advanced in PHP but I know what I’m doing. I have a view with activeForm and its model is requesting student information from a database. So I wanted to render the student view on another view and that works, however, when I submit the form it does not show the results at all. The page just refresh and go back to its normal state as if I didn’t enter any input.
How can I solve this problem? Can anyone help and point me in a right direction? I just need to show the results on the other view, that’s it!
Here’s my code:
//-- Student View –
<div class="row">
<div class="span6">
<div class="ms_form">
<?php $form = ActiveForm::begin(['options' => ['class' => 'form-vertical'], 'id' => 'student_form']) ?>
<label>Staff Look Up:</label>
<p style=""><?= Html::a("Employees", ['site/staffinfo'], ['class' => 'msoe-submit-button']) ?></p>
<hr><br>
<p><strong>Enter the following to check status:</strong></p>
<?= $form->field($model, 'firstName') ?>
<?= $form->field($model, 'lastName') ?>
<?= $form->field($model, 'jenzId') ?>
<?= Html::submitButton('Look Up', ['class' => 'ms-submit-button']) ?>
<?php $form->end() ?>
</div>
</div>
</div>
<div class="row">
<?php
if (!empty($firstnames)) {
?>
<div class="span12">
<h3>Student Standings</h3>
<table width="100%">
<tr style="background:#ebebeb; border: 1px solid #ccc;">
<th>ID Number</th>
<th>Full Names</th>
<th>Last Name</th>
<th>Current Degree</th>
<th>Student Standing</th>
<th>Major</th>
<th>Recent Year Enrolled</th>
</tr>
<tr style="border:1px solid #ccc; margin-bottom:20px;">
<td><?= $firstnames['JenzabarID'] ?> </td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['First Name'] ?> </td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['Last Name'] ?> </td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['Current Degree'] ?> </td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['Student Standing'] ?></td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['Major'] ?> </td>
<td style="border-left:1px solid #ccc;"><?= $firstnames['Recent Year Enrolled'] ?> </td>
</tr>
</table>
</div>
// – Model –
public function findFirstnames()
{
$query = new Query();
$query ->select('nm.id_num as JenzabarID,
nm.first_name as [First Name],
nm.last_name as [Last Name],
dh.div_cde as [Current Degree],
(Case sm.current_class_cde
When \'AV\' then \'Not Found\'
When \'BS\' then \'BS Graduate\'
When \'C\' then \'Certificate\'
when \'FR\' then \'Freshman\'
when \'GR\' then \'Graduate\'
when \'JR\' then \'Junior\'
when \'MS\' then \'MS Graduate\'
when \'ND\' then \'Non-Degree\'
when \'NM\' then \'Non-Matriculated\'
when \'SO\' then \'Sophomore\'
when \'SR\' then \'Senior\'
Else \'Unknown\'
End) as [Student Standing]
// – Controller –
public function actionStaffinfo()
{
$firstname = false;
$model = new staffinfo();
if (!empty($_POST)) {
$model->load($_POST);
if ($model->validate()) {
$firstname = $model->findFirstname();
}
}
return $this->render('staff-index', ['model' => $model, 'firstname' => $firstname]);
}
Below is how I rendered the student view on another view but it does not show results.
// – Faculty View –
<div class="row">
<div id="studentDetails" class="span12">
[b]<!-- Here's the Partial view in Faculty -->[/b]
<?= Yii::$app->controller->renderPartial('index', ['model'=>$model]) ?>
</div> <!--staff end -->
<div id="staffDetails" class="span12">
<h2>Search Form - Staff Laptop</h2>
<div class="msoe_form"><!-- STUDENT FORM -->
<?php $form = ActiveForm::begin(['options' => ['class' => 'form-vertical'], 'id' => 'staff_form']) ?>
<p><strong>Enter the following to check status:</strong></p>
<?= $form->field($model, 'firstName') ?>
<?= $form->field($model, 'lastName') ?>
<?= Html::submitButton('Look Up', ['class' => 'msoe-submit-button']) ?>
<?php $form->end() ?>
</div> <br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi vitae tristique neque. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
Nunc tincidunt lectus quis arcu imperdiet rutrum.
Vestibulum mattis erat ac lacus placerat efficitur. Quisque et orci in augue auctor dictum eleifend eu turpis.</p>
</div> <!--student end -->
</div><!-- row end -->