Jump to content

Post data problems - refresh adds another line. Bleh!


Recommended Posts

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.

 

 

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

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?

 

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

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

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.

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.