如何将单选按钮集成到表格中?我有这个模态,我需要在每个表上放一个单选按钮,单选按钮将包含某种值来区分表。这是表格的输出,将与单选按钮集成。
我试图在每个表上放置的单选按钮的值是此for循环中的变量$group
。
<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>
告诉我您是否需要更多信息。感谢。
修改
查看(主页)
<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>
动作
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]);
}
新错误
答案 0 :(得分:0)
您实际上可以将GridView用于表格。您将来可能会做的工作少,因为它会自动生成必要的div和boostrap样式。但是,假设你正在做这个,你想使用单选按钮。现在它有点取决于你想在一个单元格中实现多少个单选按钮。
一个例子:
<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>
这看起来像这样:
3个名称为some_name
的不同单选按钮,有3种不同的选项可供选择。选择后,同一单元格中有一个按钮,您可以单击该按钮,然后触发特定操作。