0

I have this wizard that needs to display the previous posted value

index.html

<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>

in the posted.php i have a similar form only this time i know the value from $_POST

   <form method="post" action="finish.php">
    <input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
    <input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
    <input type="checkbox" name="php" />
    <input type="checkbox" name="jquery" />
    <input type="checkbox" name="python" />
    <input type="submit" value="Submit" />
    </form>

I am having a hard time trying to come up with a solution that shows what checkbox was checked.I have seen several solutions like https://stackoverflow.com/a/11424091/1411148 but i wondering if there more solution probably in html5 or jquery.

How can i show what checkbox was checked?.The probem i am having is that <input type="checkbox" name="jquery" checked /> checked checks the checkbox and no post data can be added to show what the user checked.

Community
  • 1
  • 1
  • 1
    If you give them a value, the you can use php to echo the "checked" attribute on the input tag. `= ($_POST['jquery'] == '[VALUE'])? "checked" : ""; ?>`. The value will only pass if it checked on the form submission. – Stefan Dunn Feb 23 '14 at 13:12

1 Answers1

1

This would be a way to go:

<form method="post" action="finish.php">
    <input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
    <input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
    <input type="checkbox" name="php" <?php if (isset($_POST['php'])) echo 'checked="checked"'; ?> />
    <input type="checkbox" name="jquery" <?php if (isset($_POST['jquery'])) echo 'checked="checked"'; ?> />
    <input type="checkbox" name="python" <?php if (isset($_POST['python'])) echo 'checked="checked"'; ?> />
    <input type="submit" value="Submit" />
</form>
Ulrich Thomas Gabor
  • 6,584
  • 4
  • 27
  • 41