如果提交了表单,则选中复选框

I want to make it to so if my form is submitted then then the checkbox should be checked.

Here is what I have:

<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>

I am getting a blank page when I test it... Any help will be appreciated.

Blank is because there is an php error of your php code and you have turned error_reporting off.

  1. if($_POST['submit']) should be if (isset($_POST['submit']))

  2. echo checked should be echo 'checked';

The sample below works for me.

<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'; } ?> />

There is an error in your PHP code.Please correct it.

 <input type="checkbox" id="chk" <?php if ($_POST['submit']){ echo 'checked'; } ?> />