re5etsmyth Posted December 3, 2006 Share Posted December 3, 2006 i have a page submitting to itself, and i want to empty the $_POST array so that all of the parameters are not reposted if a user refreshes. any ideas? Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/ Share on other sites More sharing options...
willfitch Posted December 3, 2006 Share Posted December 3, 2006 You can remove all array elements using unset()unset($_POST); Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/#findComment-134189 Share on other sites More sharing options...
re5etsmyth Posted December 3, 2006 Author Share Posted December 3, 2006 i do see that it seems to empty everything, judging by:echo count($_POST);unset($_POST);echo count($_POST);however, even with the above, if i reload i get a repost notice, and the first echo will have a count like it was posted to. how do i fix that? Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/#findComment-134194 Share on other sites More sharing options...
keeB Posted December 3, 2006 Share Posted December 3, 2006 Unfortunately, this is a browser setting.To get around it, maybe a header() could be used, or a conditional <meta refresh> tag if there's post data, but that's a little clunky.It begs the question, though, why post to the same page? :D Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/#findComment-134196 Share on other sites More sharing options...
kenrbnsn Posted December 3, 2006 Share Posted December 3, 2006 Posting to the same page make redisplay of the form with the entered data easier if there are any validation errors. What you can do is if the validations succeed, jump to another page via the header() function (as long as you haven't sent any output to the browser). You then output any success message in the new script.Ken Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/#findComment-134200 Share on other sites More sharing options...
re5etsmyth Posted December 4, 2006 Author Share Posted December 4, 2006 [quote author=keeB link=topic=117165.msg477779#msg477779 date=1165121629]It begs the question, though, why post to the same page? :D[/quote]this is a plugin for wordpress, and keeping it down to 1 page is very desirable.[quote author=kenrbnsn link=topic=117165.msg477783#msg477783 date=1165123155]jump to another page via the header() function (as long as you haven't sent any output to the browser). You then output any success message in the new script.[/quote]unfortunately for me, header() requires an absolute path, and being that this is a plugin, i will never really know the path. php.net shows how to find the path when the file you are header()ing back to is in the same directory, but not in a directory several directories below, which is needed for the plugin because it is being included elsewhere.for the time being, i am posting to a different page, and using an onload to submit a form back to my original page. Link to comment https://forums.phpfreaks.com/topic/29275-empty-_post-array-so-reload-doesnt-duplicate/#findComment-134567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.