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

1
  • 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 Commented Oct 17, 2019 at 4:00

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.