Jax2 Posted April 8, 2010 Share Posted April 8, 2010 I've read up on this some and from what I understand, there is no way to clear post data. In other words, if you process a form and it adds information to the site, and then you hit refresh it asks if you want to resend the data to see that page. If you hit yes, boom, you're back on the page and it's submitted the data again. I read that one way around this was that after the data is sent, use <meta http-equiv="refresh" content="2;url=(the current page)"> which refreshes the page without sending the post data, whereby if you hit refresh afterwords, it will not require you to re-submit the post data. Unfortunately, this hasn't worked for me. It does refresh the page as it should, and it doesn't re-submit the data, but if I hit refresh on my browser again, it tries to resubmit the data. Argh! Is there a way around this? If someone leaves a comment and is waiting for a reply, I would like for them to be able to refresh the page to check for the reply without adding their own message to the box again. Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/ Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 You can clear it with a header redirect. A meta refresh will just duplicate the data from what I know. So instead of doing the refresh, just do a header redirect. If you need to keep data without processing it store data in session Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/#findComment-1038754 Share on other sites More sharing options...
Jax2 Posted April 8, 2010 Author Share Posted April 8, 2010 A header redirect must be shown before any other code otherwise you'll get a cannot modify headers error, won't you? I need to refresh the page AFTER the data has been entered into the database, so I need it to process first, then redirect. :/ What i mean is, if I put in the header redirect code, won't it see that, skip anything below it and redirect to the original page before getting the chance to process the form data? Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/#findComment-1038763 Share on other sites More sharing options...
Pikachu2000 Posted April 8, 2010 Share Posted April 8, 2010 If I'm reading this right, you want the data to go away after the form is submitted, and validation and database queries executed successfully, correct? Just reinitialize the $_POST array . . . $_POST = array(); Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/#findComment-1038783 Share on other sites More sharing options...
premiso Posted April 8, 2010 Share Posted April 8, 2010 A header redirect must be shown before any other code otherwise you'll get a cannot modify headers error, won't you? I need to refresh the page AFTER the data has been entered into the database, so I need it to process first, then redirect. :/ What does needing to process first have to do? Surely you are not displaying data while you are processing are you? If so you probably should not. You would do well to read the following: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html http://www.slunked.com/blog/php/2010/01/how-to-fix-header-already-sent-error-in-php Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/#findComment-1038997 Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 premiso is right. Use a header() redirect to take the user to a 'thankyou' page. If they refresh, it will just refresh the thankyou page. I think you misunderstand header(), it can be used after any PHP code, as long as no output has been sent to the browser yet. Quote Link to comment https://forums.phpfreaks.com/topic/197956-post-data-problems-refresh-adds-another-line-bleh/#findComment-1040075 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.