Reputation: 41
To put it simple, is there a way to output the POST inputs of the user back in the textboxes that he used in the previous page?
Example:
Page one
Text box: <value here>
Text box: <value here>
Text box: <value here>
Let's say the user decided to press next(which leads the user to page two) but suddenly decided to go back to do some minor changes(page one).
I have a weird design. Since I do not know how to keep the variables that i used in page one, I decided to input it to the database right after pressing next. But if I go back to page 1, it will create a new row of data. I'm kinda confused, if you have any idea how to do this efficiently, please suggest it. Thanks!
Upvotes: 0
Views: 832
Reputation: 26124
Now would probably be a good time to bite the bullet and refactor. Better to get it over with now before jumping through hoops and hurdles to make it work, leading to code that is cumbersome at best, and incomprehensible at worst.
Like others here have suggested, you can save the form values in the $_SESSION
variable. Your best bet may be to refactor the form so that all of the data is saved at the very last page, but if that is unfeasible, then after page 1, save the form values AND the unique id of the data-set (such as a primary key value) to $_SESSION
at the top of page 2.
If a user then presses the back button, and isset($_SESSION['myform']['id'])
, then you can re-populate the form elements with the saved values. Likewise, if at the top of page 2, $_SESSION['myform']['id']
is set, then there is no need to insert a new row, but just update the existing row with the new form data from $_REQUEST
.
Upvotes: 1
Reputation: 303
Store them as a $_SESSION variable. For example, set $_SESSION['input'] = 24. Then you can call that value on other pages until you end the session.
http://php.net/manual/en/reserved.variables.session.php
Upvotes: 0