Page 1 of 1

feedback form

Posted: Wed Jul 10, 2002 8:51 pm
by rats
I have a problem with a feedback script like the ones they have at the bottom of the function pages on http://www.php.net They let people input there comments at the bottom of a web page.

Anyway the problem is that the user fills out the form and submits it (it posts to itself) and the new post it displayed along with the rest but if you press the refresh button at this point the sscript will add the post twice. I have tried unsetting the posted variables ( unset($var)) but that dosent work.

any ideas?

Posted: Wed Jul 10, 2002 8:54 pm
by protokol
How do you store each post? Do you insert them into a database???

Or you could use sessions:

Code: Select all

session_start();

if (isset($_SESSIONї'posted']) && $_SESSIONї'posted'] == false) {
   // post message code here
   $_SESSIONї'posted'] = true;
}
Now, even if the user reloads the page, the new message will not be posted because the $_SESSION['posted'] will be TRUE, which doesn't match the above condition, and therefore, doesn't add the new message.

Posted: Wed Jul 10, 2002 9:38 pm
by rats
they are stored in a database.

Posted: Thu Jul 11, 2002 4:13 am
by gnu2php
You could try redirecting to a "thank you" page, so that when the user clicks refresh, it reloads the "thank you" page instead of resubmitting the data.

Code: Select all

$thank_you_page = "thank_you.php";

$new_location = "http://".$_SERVERї'HTTP_HOST'].dirname($_SERVERї'PHP_SELF'])."/".$thank_you_page;

header("Location: $new_location");
:arrow: (See http://www.php.net/manual/en/function.header.php for more information about the header() function)

:arrow: (You might also want to see a similar thread at http://www.devnetwork.net/forums/viewtopic.php?t=1410 )