我想这样做,如果我的表单已提交,那么应该选中复选框。
这就是我所拥有的:
<input type="checkbox" id="chk" <?php if ($_POST['submit']){ echo checked } ?> />
HTML:
<form id="form1" enctype="multipart/form-data" action="" method="post">
//Stuff here
<input name="submit" type="submit" value="Upload" />
</form>
我在测试时得到一个空白页...任何帮助都将受到赞赏。
答案 0 :(得分:3)
空白是因为您的PHP代码存在php错误而您已关闭error_reporting
。
if($_POST['submit'])
应为if (isset($_POST['submit']))
echo checked
应为echo 'checked';
以下示例适用于我。
<form id="form1" enctype="multipart/form-data" action="" method="post">
//Stuff here
<input name="submit" type="submit" value="Upload" />
</form>
<input type="checkbox" id="chk" <?php if (isset($_POST['submit'])){ echo 'checked'; } ?> />
答案 1 :(得分:0)
您的PHP代码有错误。请更正。
<input type="checkbox" id="chk" <?php if ($_POST['submit']){ echo 'checked'; } ?> />