我有以下我目前默认选中的复选框
<tr>
<td> </td>
<td> </td>
<td align="right">Include In Top Sellers?</td>
<td>
<input type="hidden" name="include_top" value="0">
<input type="checkbox" name="include_top" id="include_top" value="1"
<?php echo (($_POST["include_top"] == "1") or ($res["include_top"] == "1")) ? "checked='checked'" : ""; ?>
autocomplete="off" checked/>
</td>
</tr>
它在PHP文件中运行。问题是,如果我取消选中并保存它,我需要它保持不受控制。我仍然希望检查默认值。 php文件是Magento中新产品设置的模板。不确定会话或cookie是否会对此有所帮助。
答案 0 :(得分:0)
试试这个:
<tr>
<td> </td>
<td> </td>
<td align="right">Include In Top Sellers?</td>
<td>
<input type="hidden" name="include_top"
value="0"><input type="checkbox"
name="include_top"
id="include_top"
value="1" <?php echo (($_POST["include_top"] == "1") or ($res["include_top"] == "1") or (!array_key_exist('include_top', $_POST))) ? "checked='checked'" : ""; ?>
autocomplete="off"/>
</td>
</tr>