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 Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/ 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. Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1021812 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 Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1021988 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> Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1022166 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 Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1022212 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. Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1022283 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 Link to comment https://forums.phpfreaks.com/topic/194207-php-error-checking-forms-and-redirection/#findComment-1023709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.