etxnreg Posted July 19, 2009 Share Posted July 19, 2009 Hi, I am a beginner in this area, and need help with following. I have lot of POST variables for the php script. Therefor I have created more than one HTML page with a next button between them. The problem is when I in the last HTML page request the php script only the POST variables from the last page are transferred to the php script. How should I do so all variables are transferred to the php script? BR Niklas? Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/ Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 pass them as a session variable/array or on "next" page, echo the previous info out as hidden fields. Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-878241 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 Save the information between requests. session_start(); if (!empty($_POST)) { if (!isset($_POST['wizard_finished'])) { // preferably only present on the last step $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST); } else { //wizard finished $_POST = $_SESSION['_POST']; //process as if it were one-page request } } Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-878243 Share on other sites More sharing options...
etxnreg Posted July 20, 2009 Author Share Posted July 20, 2009 Hi, Thanks for the quick answer. I need some more hints how actually I get the input box value copy to the session variable when next putton is pushed. My code is as following: <?php session_start(); ?> <html> <head> </head> <body> <form name="form1" method="POST" action="interface.php" style="margin:0px"> <input name="test1" value="test1" type="text" style="position:absolute;width:200px;left:18px;top:108px;z-index:0"> <input name="formbutton1" type="submit" value="next" style="position:absolute;left:72px;top:202px;z-index:1"> <?php $_SESSION['test1']=$_POST[test1]; ########## This line probably wrong############## ?> </form> </body> </html> Thanks Niklas Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-878490 Share on other sites More sharing options...
chokies12 Posted July 20, 2009 Share Posted July 20, 2009 for much easier debuggin why dont you separate your html codes from your php codes. <?php session_start(); extract($_POST); // extract $_POST array so you wont be type $_POST always $_SESSION['test1']=$test1; ?> <html> <head> </head> <body> <form name="form1" method="POST" action="interface.php" style="margin:0px"> <input name="test1" value="test1" type="text" style="position:absolute;width:200px;left:18px;top:108px;z-index:0"> <input name="formbutton1" type="submit" value="next" style="position:absolute;left:72px;top:202px;z-index:1"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-878506 Share on other sites More sharing options...
etxnreg Posted July 20, 2009 Author Share Posted July 20, 2009 Hi, I have now separated the php code from the HTML. Unfortunately I have still problem to transfer the input box value to another php script. if I change following line $_SESSION['test1']=$test1; to $_SESSION['test1']=hello the value is transferred to the next php script. It seems to be something with the input box. Any suggestions? BR Niklas Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-878857 Share on other sites More sharing options...
ignace Posted July 21, 2009 Share Posted July 21, 2009 Save the information between requests. session_start(); if (!empty($_POST)) { if (!isset($_POST['wizard_finished'])) { // preferably only present on the last step $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST); } else { //wizard finished $_POST = $_SESSION['_POST']; //process as if it were one-page request } } This code isn't entirely correct, it will delete any post values on the last page: $_POST = array_merge($_SESSION['_POST'] /*stored values*/, $_POST /*post values from the last page*/); Should fix this problem. Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-879479 Share on other sites More sharing options...
ignace Posted July 21, 2009 Share Posted July 21, 2009 Do realize that this code has parts missing like validation. And if you would use this code as-is you will not be able to display form specific error codes. Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-879536 Share on other sites More sharing options...
etxnreg Posted July 24, 2009 Author Share Posted July 24, 2009 Hi, Thanks for all support. The script works now. BR Niklas Quote Link to comment https://forums.phpfreaks.com/topic/166538-solved-how-to-remember-post-variabe-from-html/#findComment-881786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.