Jump to content

Archived

This topic is now archived and is closed to further replies.

jkkenzie

Clear post data

Recommended Posts

What do you mean?

 

The $_POST array is populated when a form is submitted.

 

Ken

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
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);

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

×
×
  • 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.