jkkenzie Posted August 21, 2008 Share Posted August 21, 2008 Is there a way i can clear $_POST data bfore i load a page Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/ Share on other sites More sharing options...
kenrbnsn Posted August 21, 2008 Share Posted August 21, 2008 What do you mean? The $_POST array is populated when a form is submitted. Ken Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-621937 Share on other sites More sharing options...
jkkenzie Posted August 21, 2008 Author Share Posted August 21, 2008 OK , i had not clearly thought of this. Let me refrace myself. Is there a way i can clear my form using php AFTER my form loads? OR just after the form POSTS? Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-621971 Share on other sites More sharing options...
The Little Guy Posted August 21, 2008 Share Posted August 21, 2008 don't use the HTML attribute value? Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-621974 Share on other sites More sharing options...
jkkenzie Posted August 28, 2008 Author Share Posted August 28, 2008 Hi! After i click Submit the page saves all data to database and comes back to the same form, BUT the POST data is still there, and the form's input boxes still will show the DATA which was saved SINCE this is one file (php) doing all the processing. I wanted after the saving of DATA Goes successful, IT CLEARS the POST data so that the user input NEW data. Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-627583 Share on other sites More sharing options...
Psycho Posted August 28, 2008 Share Posted August 28, 2008 The data can only populate the form if you specifically write code for it to do so. However, I am going to make an assumption that you want the form to be populated with the POSTed data in the event there is a validation error. Well, I would still suggest writing your code such that the form is only re-populated when a validation fails, but a "quick fix" would be to use unset() unset($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-627586 Share on other sites More sharing options...
kratsg Posted August 28, 2008 Share Posted August 28, 2008 This is just one thing I've always struggled with cause there's so many reasons why you don't want a user to refresh the page. The best (and most effective) way of doing this is just to stick the script that handles the form on another page, and at the end add a header redirect: <?php header('Location:http://www.somesite.com/myform.php'); ?> Unless the script is unusually large and takes minutes to process, you shouldn't see the script-processing page. You can also use the script page to re-populate the form, display the errors, have it submit and re-direct back to the actual html form. (if that makes sense). form.html (this contains your form and submits to formsubmit.php) formsubmit.php (this contains the script for handling the form) If for some reason, the validation fails, formsubmit.php will then echo out the form again with all the values filled in, pointing out the errors shown. This new form will submit to formsubmit.php, which if successful, redirects back to form.html. Does that description make sense? Quote Link to comment https://forums.phpfreaks.com/topic/120701-clear-post-data/#findComment-627588 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.