feedback form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

feedback form

Post 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?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

Post by rats »

they are stored in a database.
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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 )
Post Reply