popcop Posted July 31, 2011 Share Posted July 31, 2011 can anyone tell me how to redirect to a new page after a form is submitted currently i have an echo that displays 'Thank you' but i want to take them to a new page thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/ Share on other sites More sharing options...
wildteen88 Posted July 31, 2011 Share Posted July 31, 2011 You can use header to redirect the user to another page header('Location: newpage.php'); Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249815 Share on other sites More sharing options...
PFMaBiSmAd Posted July 31, 2011 Share Posted July 31, 2011 After you have successfully processed a form submission, you actually need to redirect to the same page as the form's action="" attribute to change the browser's history for that page from a form submission to a GET request so that the browser won't attempt to resubmit the data should you browse back to that page. Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249820 Share on other sites More sharing options...
popcop Posted July 31, 2011 Author Share Posted July 31, 2011 using header() returned an error Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249822 Share on other sites More sharing options...
wildteen88 Posted July 31, 2011 Share Posted July 31, 2011 using header() returned an error Probably because you have some form of output before the use of that function. You cannot echo/print anything to the screen before the use of header(). Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249828 Share on other sites More sharing options...
popcop Posted July 31, 2011 Author Share Posted July 31, 2011 its ok i forgot i had an echo at the top of that page that i didnt need, ive removed it and it works now thanks Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249834 Share on other sites More sharing options...
wildteen88 Posted July 31, 2011 Share Posted July 31, 2011 Sort your code out so there is no output before the use of header(). Or use output buffering for a lazy fix. Another option would be to set a html meta redirect or use JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/243386-redirect-to-a-new-page-after-form-submitted/#findComment-1249836 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.