PHP / HTML 复选框按钮

PHP / HTML checkbox button

我有一个 GPA 计算器表格,当用户输入他们的信息时,我希望它在屏幕上保持填充状态。

    E-mail: <input type="text" size="35" name="email" value="<?php echo $email; ?>">
    <span class="error"><?php echo $emailErr; ?></span>
    <br><br>

    <input type="checkbox" name="agree" >
    I agree to the terms and conditions of this website.
    <span class="error"><?php echo $agreeErr; ?></span>
    <br><br>

我的其他变量没有问题,但我无法让我的复选框留在屏幕上。当用户点击提交时,复选框将再次取消选中。如何让它在屏幕上保持选中状态?

谢谢!

通过反复试验,我找到了一个简单的解决方案:

<input type="checkbox" name="agree" 
value="agree" <?php if(isset($_POST['agree'])) echo "checked='checked'";?> 
>I agree to the terms and conditions of this website.
<span class="error"><?php echo $agreeErr; ?></span>

以防其他人遇到同样的问题!