I'm currently experiencing a strange issue I can't find an explanation for. Here is the code:
<html>
<body>
<form enctype="multipart/form-data" action="" method="post">
<input type="submit" name="button1" value="Edit">
</form>
<form enctype="multipart/form-data" action="" method="post">
<?php
if (isset($_POST["button1"])){
echo "Edit button clicked<br>";
echo "Edit button clicked<br>";
echo "Edit button clicked<br>";
echo "Edit button clicked<br>";
echo "Edit button clicked<br>";
echo "<input type=\"submit\" name=\"button2\" value=\"Save changes\">";
}
?>
</form>
<br><br><br><br><br><br><br>
<?php
if (isset($_POST["button2"])){
echo "Save Changes button clicked";
};
?>
</body>
</html>
What happens in this case, when clicking the button "Edit", you see 5 times "Edit button clicked". When clicking then on the button "Save changes", all the previous "Edit button clicked" text is gone and only the "Edit" button is visible and the text "Save Changes button clicked" with a lot of white lines in between.
How can I ensure that the "Edit button clicked" lines are still visible?
Another thing is, when you change $_POST["button2"] by $_POST["bla"] it will show the initial page. Why doesn't it leave everything visible?
Thanks a lot for your help ;-)
So you have 3 steps in your form, when switching from step 1 to step 2 the data posted from step 1 is given, when switching from step 2 to step 3 the data posted from step 2 is given.
If you want too carry the data from step 1 - 3 then you have to use hidden input fields or the session.
But you should seperate some of your code to controll the flow better
Use: var_dump($_POST);
outside all conditions on your page and see what happens.