【发布时间】:2019-11-19 19:24:38
【问题描述】:
我正在实现一个项目列表,每个项目都有一个复选框。我目前可以看到哪些复选框已被选中,但我想要做的是检查它们是否都已被选中。我该如何实现?
这是我的代码:
<form action="" method="post">
<?php
echo "<table>
<tr>
<th>Customer ID</th>
<th>Report ID</th>
<th>Report message</th>
<th>Device</th>
<th>Device no.</th>
<th>Barcode</th>
<th>IMEI</th>
<th>Sale-date</th>
</tr>";
while ($row2 = $clientUsername->fetch_assoc()) {
$_SESSION['cl_username'] = $row2["username"];
while ($row = $message->fetch_assoc()) {
$_SESSION['accept'] = $row["acceptance"];
$_SESSION['client_comment'] = $row["message"];
$_SESSION['name'] = $row["name"];
$_SESSION['sales_date'] = $row["sales_date"];
$_SESSION['date_sent'] = $row["date_sent"];
$_SESSION['countable_array'] = $row;
?>
<?php if ($row['acceptance'] == 3) {
echo "<tr> <td>
" . '<input type=checkbox name=devices[] value=' . $row['dev_id'] . '>' . "
</td> <td>" . $cus_id . " </td> <td>" . $rep_id . "</td> <td>" . $_SESSION['client_comment'] . "</td> <td>" . $_SESSION['name'] . "</td> <td>" . $row["device_no"] . "</td> <td>" . $row["barcode"] . "</td> <td>" . $row["serial_imei"] . "</td> <td>" . $row["serial_no"] . "</td> <td>" . $row["sales_date"] . "</td></tr>";
echo "</table>";
}
}
}
</form>
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['rejected'])) {
if (count($count_devices) == 1) {
...
}
}
【问题讨论】:
-
I currently can see which checkboxes have been checked- 您在该代码中的哪个位置执行此操作?我看不到任何表单提交和请求变量的检查。 -
@Nawin 这个问题没有用 JavaScript 或 jQuery 标记... :)
-
您是否尝试检查 $_POST['devices'] 是否为空? if (empty($_POST['devices'] ) { //不是所有的复选框都是选中的 }
-
@ConstantinGroß 我刚刚更新了我的问题。我添加了其他代码。