user827391012 user827391012 - 1 month ago 11
HTML Question

Integrate radio button into table PHP / Yii 2

how can i integrate a radio button into a table? I have this modal where I need to put a radio button on each table, the radio button will contain some kind of value to differentiate the tables. Here is an output of the table that will be integrated with a radio button.

enter image description here

The value of the radio button I am trying to put on each table is the variable

$group
in this for loop.

<div class="modal-body">
<?php $getSectionGroup = SiteController::Getsectiongroup(); ?>
<?php for ($group=1; $group <= $getSectionGroup; $group++): //group variable will be used in getBlock ?>
<?php $getBlock = SiteController::GetBlock(Yii::$app->user->identity->curriculumcode, Yii::$app->user->identity->year,
Yii::$app->user->identity->term, $group); ?>
<table class="table table-bordered" id="studentTable">
<th>Subject</th>
<th>Schedule</th>
<th>Section</th>
<th>Action</th>
<th>Slots</th>
<th>Status</th>
<?php foreach($getBlock as $values): ?>

<tr>
<td><?= $values['subjectcode']; ?></td>
<td><?= $values['schedday'] . ' ' . $values['schedtime'] ?></td>
<td><?= $values['section'] ?></td>
<td><?= '....' ?></td>
<td><?= $values['slots'] ?></td>
<td><?= '....' ?></td>
</tr>

<?php endforeach; ?>
</table>
<?php endfor; ?>
</div>


Tell me if you need more info. Thanks.

EDIT

View (Mainpage)

<div class="modal-body">

<?php $getSectionGroup = SiteController::Getsectiongroup(); ?>
<?php for ($group=1; $group <= $getSectionGroup; $group++): //group variable will be used in getBlock ?>
<?php $getBlock = SiteController::GetBlock(Yii::$app->user->identity->curriculumcode, Yii::$app->user->identity->year,
Yii::$app->user->identity->term, $group); ?>

<form action="" method="post">
<input type="radio" name="radio" value="<?php echo $group?>">
<table class="table table-bordered" id="studentTable">
<th>Subject</th>
<th>Schedule</th>
<th>Section</th>
<th>Action</th>
<th>Slots</th>
<th>Status</th>
<?php foreach($getBlock as $values): ?>

<tr>
<td><?= $values['subjectcode']; ?></td>
<td><?= $values['schedday'] . ' ' . $values['schedtime'] ?></td>
<td><?= $values['section'] ?></td>
<td><?= '....' ?></td>
<td><?= $values['slots'] ?></td>
<td><?= '....' ?></td>
</tr>

<?php endforeach; ?>
</table>
<?php endfor; ?>

</div>
<div class="modal-footer">
<input type="submit" value="Go">
<?php // Html::a('<b>Submit</b>',
// ['site/addblock'],
// ['class' => 'btn-info btn-transparent btn-large', 'data-method' => 'get']) ?>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>


Action

public function actionMain(){
// $model = new MainModel();
if (Yii::$app->user->isGuest) {
//return $this->goHome();
// $this->layout = 'userlayout';
// return $this->render('mainpage');
$this->redirect('site/index',302);
}
$output = var_dump(Yii::$app->request->post('blockform'));
$this->layout = 'userlayout';
return $this->render('mainpage', ['outputblockform' => $output]);
}


New error

enter image description here

Answer

You can actually use GridView for table. You may get less work to do in future because it automatically generates necessary divs and boostrap style. But let's say you're doing this and you want to use radio button. Now it a little depends on how many radio buttons you want to implement into one cell.

One example:

<td>
<form action="" method="post">
    <input type="radio" name="some_name" value="1"> Action1
    <input type="radio" name="some_name" value="2"> <?= $values['subjectcode']; // Or this ?>
    <input type="radio" name="some_name" value="3"> Action3
    <br><input type="submit" value="Go">
</form>
</td>

This will look something like this:

3 different radio buttons with name some_name and there are 3 different options to select from. Once selected, there is a button in the same cell that allow you to click on it and then specific action is triggered.

Comments