Jump to content

Clear post data


jkkenzie

Recommended Posts

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.

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.