jbradley04 Posted March 5, 2010 Share Posted March 5, 2010 Hello all! I have a question... I have a form in which I am doing the error checks server side with PHP... So if they submit this form and they forget a field, it redirects them back to the original form and an erro message pops up... The problem is every time they get redirected back to original form they have to enter all the information back in! Is there a way to pass these posted variables back to original form? I hope this makes sense! Thanks for your help! J Quote Link to comment Share on other sites More sharing options...
Deoctor Posted March 5, 2010 Share Posted March 5, 2010 u can use the sessions/ cookies to store the values and then post them back to the form if they exists. Quote Link to comment Share on other sites More sharing options...
jbradley04 Posted March 5, 2010 Author Share Posted March 5, 2010 Great! So can you just briefly explain how that would work? I am Not that great of a programmer! Kind of a hobby more then anything else but still learning a lot!!! Thanks J Quote Link to comment Share on other sites More sharing options...
freakstyle Posted March 6, 2010 Share Posted March 6, 2010 Here's a basic example: <?php // Start the session. session_start(); $data = $_POST; if(isset($data['submit']) && !empty($data['submit'])) { // Set the posted data to a unique key in the global session data array. $_SESSION['posted_values'] = $data; } ?> <!--// Input fields shown how to set the value from the session and then the submit button to go along with my form check above. //--> <form> <input type="text" name="email" value="<?= isset($_SESSION['posted_values']['email']) && !empty($_SESSION['posted_values']['email'])? $_SESSION['posted_values']['email'] : null; ?>" /> <input type="submit" value="submit" name="submit" /> </form> Quote Link to comment Share on other sites More sharing options...
jbradley04 Posted March 6, 2010 Author Share Posted March 6, 2010 SWEET!!!!!!!! Thank you so much! Works like a charm! Now one final question? Should I use session_destroy(); after I set the seesion.. If I do not what happens to data? Thanks for all your help! J Quote Link to comment Share on other sites More sharing options...
cags Posted March 6, 2010 Share Posted March 6, 2010 If you view the manual, it has a good explanation of both what session_destroy does, and how to actually 'properly' close a session when your done with it. Quote Link to comment Share on other sites More sharing options...
jbradley04 Posted March 9, 2010 Author Share Posted March 9, 2010 Great! Thanks for everyones help! I think I got it! J Quote Link to comment 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.