php - 在 PHP Post 数组中插入复选框
问题描述
对不起,愚蠢的问题。我有一个带有多个动态生成的复选框的表单,我想将它们插入到 post 数组中以将它们移动到下一页然后操作它们。
表格:
<form action="campcreate.php" class="form" method="post">
<label for "campName">Campaign Name:</label>
<input type="text" id="campName" class="form-control" name="campName" placeholder="Campaign Name" required minlength="6" autofocus>
<label for "notes">Description:</label>
<textarea class="form-control" name="notes" rows="5" id="notes" placeholder="Add any useful notes or descriptions here"></textarea>
<h3>Select committee memmbers:</h3>
<p>Committee members can be changed as required, all members selected as committee members will be able to view documents, meetings etc. connected to the campaign.</p>
<p>Assigning a committee member does <strong>not</strong> grant them any different admin privillages on the site.</p>
<?php getnames(); ?>
<div>
<button type="submit" class="btn btn-success float-right" id="create">Next</button>
<button type="button" class="btn btn-primary float-right" id="restart">Back</button>
</div> <!--Form Div--->
</form>
包含的功能:
function getnames(){
global $conn;
$sqlga = "SELECT user_id, user_first, user_last FROM users WHERE (usr_acrive= 1) AND (perm!=0) ORDER BY user_last ASC";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sqlga);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
if ($row['user_id']!=$_SESSION['user_id']){
$checked="";
}else{
$checked="checked disabled";
}
echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"> '.$row['user_first'] . ' '. $row['user_last'] . '<br>';
}
}
我想将这些复选框(正确显示)转发到下一页,但我不知道如何在帖子中包含这些复选框,将自动选择一个框(创建帖子的用户)但最多可以说可以勾选其他 100 个框。
我试过回显,但我只能看到文本框。
欢迎任何指点。
解决方案
发布信息由输入标签的名称发送
您正在循环并添加具有相同名称的输入:
echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"> '.$row['user_first'] . ' '. $row['user_last'] . '<br>';
您应该在回显时尝试创建一个唯一的名称,具体取决于您需要的操作...
例如(在 foreach 循环内):
$i++;
echo '<input type="checkbox"'.$checked.' value="'. $row['user_id'] .'" name="userid"'. $i. '> '.$row['user_first'] . ' '. $row['user_last'] . '<br>';
推荐阅读
- powershell - 将 Powershell Exchange EWS 脚本身份验证转换为 Oauth 获取错误:受众声明值对当前资源无效
- jquery - Fancybox 更改下一个和上一个图像源
- amazon-web-services - AWS CLI“拒绝访问”错误是否意味着权限错误或密钥错误?
- php - PHP验证后Jquery在Div中预览视频而图像不工作
- ios - SearchBar:动态变化结果
- javascript - 如果满足条件,角度动画
- javascript - 在什么触发器上,我可以通过 MSAL 的 msalObj.acquireTokenSilent() 方法静默获取 id_token?
- python-3.x - 日期截断后乘以熊猫数据框和字典
- css - SASS:map-get 不返回变暗可用的颜色
- javascript - 基于 18 的倍数的 JavaScript 数字规则