-1

I have a GPA calculator form, and when a user enters their information, I want it to stay populated on the screen.

    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>

I have no problem with my other variables, but I cannot get my checkbox to stay on the screen. When the user hits submit, the checkbox will un-check again. How can I make it stay checked on the screen?

Thank you!

  • Check the checkbox value on server: As I remember, `$_POST['agree']` maybe *true*. When you re-populate to the form, add attribute `check== $_POST['agree'] ?>` to the checkbox Btw, I dont think this question is relevant to `computer-science` – Kien Pham Oct 17 '19 at 04:00

1 Answers1

0

Through trial and error, I have found a simple solution:

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

Just in case anyone else gets stuck on this same problem!