Ink*_*231 2 php forms checkbox checked
我知道如何在出现错误时保持表单提交复选框,但我现在有一个不同的问题.我正在使用同名的复选框,人们可以点击1或多个.我希望它只是保持复选框的用户签填写如果有喜欢的,如果他们检查q1中的Q1B一个问题,但不是Q1C我只想Q1 A和Q1B上的错误再装入时表现出检查.现在,在出错时,将检查所有相同名称的复选框.我已经尝试将名称更改为q1 [],但这不起作用.你能看一下,让我知道如何解决这个问题吗?
这是我的代码.
<tr>
<td style="width: 124px" class="style15">Tape Recorder<?php if(isset($problems['tape[]'])) {?><font color="red">*</font><?php } ?></td>
<td class="style9">
<input name="tape[]" id="tape1" type="checkbox" value="used before," <?php if(isset($_POST['tape[]'])) echo "checked"; ?>
</td>
<td class="style9">
<input name="tape[]" id="tape2" type="checkbox" value="helpful in past," <?php if(isset($_POST['tape[]'])) echo "checked"; ?> </td>
<td class="style9">
<input name="tape[]" id="tape3" type="checkbox" value="requesting from DACC" <?php if(isset($_POST['tape[]'])) echo "checked"; ?> </td>
<td class="style9">
<input name="tape[]" id="tape4" type="checkbox" value="NA" <?php if(isset($_POST['tape[]'])) echo "checked"; ?></td>
</tr>
<tr>
<td style="width: 124px">Note Taker <?php if(isset($problems['note'])) {?> <font color="red">*</font><?php } ?></td>
<td class="style9">
<input name="note" type="checkbox" value="used before," <?php if(isset($_POST['note'])) echo "checked"; ?>
</td>
<td class="style9">
<input name="note" type="checkbox" value= "been helpful in the past," <?php if(isset($_POST['note'])) echo "checked"; ?>
<td class="style9">
<input name="note" type="checkbox" value= "requesting from DACC" <?php if(isset($_POST['note'])) echo "checked"; ?>
<td class="style9">
<input name="note" type="checkbox" value="NA" <?php if(isset($_POST['note'])) echo "checked"; ?>
</tr>
Run Code Online (Sandbox Code Playgroud)
一个快速而肮脏的解决方案是:
<input name="tape[]" id="tape[]" type="checkbox" value="NA" <?php if(isset($_POST['tape']) && is_array($_POST['tape']) && in_array('NA', $_POST['tape'])) echo 'checked="checked"'; ?> />
Run Code Online (Sandbox Code Playgroud)
为此,您需要明确更改每个不同答案的"NA"部分.虽然我会查看类似于重复复选框的循环或回调函数来确定是否回显checked=checked.