首页 > 解决方案 > 如何从表结构化数据中检索复选框值?

问题描述

我有一个表格,每列都有复选框,如下所示:

在此处输入图像描述

此表的代码:

'<form action="ecfcoursedata.php" method="post">';
"<table width='50%'>";
'<tr><th>e-Competence Level</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th></tr>';  
  foreach ($tree as $key => $term) {
    '<tr><td>' . $term->name . '</td>'
    for($i=1; $i<=5; $i++) {
      '<td><input type="checkbox" name=' . $term->name . '-' . $i . '></td>';
    }
    '</tr>';
  }
 '</table></div>';
 '<div class="ecf-submit"><input type="submit" value="Submit" name=' . $arg0 . '></div></form>';

当我单击提交时,我需要检查每一行和特定列的值。我怎样才能做到这一点?请在这方面帮助我。

标签: phphtmlformscheckbox

解决方案


在您的 HTML 中假设它是

<input type="checkbox" name="test" value="value1">

当您提交到 php 时,您可以使用

isset($_POST['test']);

或者

if ($_POST['test'] == 'value1'){}

或者

$variable = $_POST['test'];

推荐阅读