2 回答
TA贡献2016条经验 获得超9个赞
例子:
<?php
$options = [
["artistid" => 1, "req_id" => 1, "requirement" => "Microphone"],
["artistid" => 1, "req_id" => 2, "requirement" => "Table"],
["artistid" => 1, "req_id" => 3, "requirement" => "Chair"],
["artistid" => 1, "req_id" => 4, "requirement" => "Microphone Stand "],
["artistid" => 1, "req_id" => 5, "requirement" => "Personal Artifacts"],
["artistid" => 1, "req_id" => 6, "requirement" => "Set Dressing"],
["artistid" => 1, "req_id" => 7, "requirement" => "Raised Step "]
];
$checkedOptions = [2, 7];
foreach ($options as $option) {
?>
<label class='checkbox'>
<input type="checkbox" name="requirement[]" value="<?= $option['req_id']?>" <?= in_array($option['req_id'], $checkedOptions) ? 'checked' : '' ?> >
<?= $option['requirement'] ?>
</label>
<br>
<?php
}
?>
TA贡献1826条经验 获得超6个赞
您需要一个条件语句来查看变量是否设置为来自$_POST[]或$row[]数组的输入字段的名称,以及是否设置回显checked输入字段中的属性。如果您动态创建输入列表,则需要对 value 属性执行相同的操作。
<input type='checkbox' name='microphone' value='$eqid' <?php if($eqname === "microphone"){ echo 'checked'; }>
<input type='checkbox' name='table' value='$eqid' <?php if($eqname === "table"){ echo 'checked'; }>
<input type='checkbox' name='chair' value='$eqid' <?php if($eqname === "chair"){ echo 'checked'; }>
<input type='checkbox' name='microphone_stand' value='$eqid' <?php if($eqname === "microphone_stand"){ echo 'checked'; }>
<input type='checkbox' name='personal_artifacts' value='$eqid' <?php if($eqname === "personal_artifacts"){ echo 'checked'; }>
<input type='checkbox' name='set_dressing' value='$eqid' <?php if($eqname === "set_dressing"){ echo 'checked'; }>
<input type='checkbox' name='raised_step' value='$eqid' <?php if($eqname === "raised_step"){ echo 'checked'; }>
<input type='checkbox' name='other' value='$eqid' <?php if($eqname === "other"){ echo 'checked'; }>
- 2 回答
- 0 关注
- 77 浏览
添加回答
举报