I have a 3 forms on 3 different pages. Each form upon submit will go to the next form page as follows:
<form action="/form2.php" method="post>
<input type="submit" name"next" value="next">
</form>
<form action="/form3.php" method="post>
<input type="submit" name"next" value="next">
</form>
<form action="/form4.php" method="post>
<input type="submit" name"next" value="next">
</form>
If the user as at form4.php after submission from form2.php and form3.php,
I need to create a back button in each page such that if a user clicks on the button the previous page still displays the form values(Even the user goes back from last form to first form)
How do I acheive it? Is using session variables or post data only way to do it?
Sessions would be your best option IMO. In each formX.php file, be sure to start the session:
And then at the beginning of each script, check for $_POST variables. If you have any (i.e submitted from previous form) add them to the $_SESSION array.
In addition, when rendering the form on the page, use whatever value is in the $_SESSION variable for that text field. If it is empty or not set, then the user will be presented with an empty textbox.
[SECURITY DISCLAIMER] I should warn you that haplessly taking user input and throwing around in your code is a recipe for security disasters. Make sure you filter input and escape output when doing all of this!