Greyfish
05-10-2008, 02:16 AM
What is the best way to stop a contact form from sending information twice if the user refreshes the page?
|
Click to See Complete Forum and Search --> : Stop form from sending twice? Greyfish 05-10-2008, 02:16 AM What is the best way to stop a contact form from sending information twice if the user refreshes the page? Yelgnidroc 05-10-2008, 03:05 AM Try having a session variable $_SESSION['already_submitted'] Set it to TRUE after processing the form. Only process the form if it's not TRUE apulmca2k4 05-10-2008, 04:06 AM Redirect at another thanks page after processing data of form. Greyfish 05-10-2008, 12:04 PM If don't like sending them to a page thats sole purpose is to say "Thankyou" I'd rather just keep it all on one page. I can't figure out how to get this session variable thing to work, what is wrong with this? session_start(); $_SESSION['sent'] = "false"; if (isset($_POST["submit"])){ if ($_SESSION['sent'] == "false"){ $name = $_POST["name"]; $email = $_POST["email"]; $to = "example@example.com"; $subject = $_POST["subject"]; $message = $_POST["message"]; $body = "Full Name: $name\n". "E-mail Address: $email\n". "Message: $message"; $header = "From: $email"; mail($to, $subject, $body, $header); $_SESSION['sent'] = "true"; } } Yelgnidroc 05-10-2008, 12:52 PM You are always setting $_SESSION['sent'] = "false"; May be better to do something like: if(!isset($_SESSION['sent'])) $_SESSION['sent'] = "false"; if (isset($_POST["submit"])){ if ($_SESSION['sent'] == "false"){ $name = $_POST["name"]; $email = $_POST["email"]; $to = "example@example.com"; $subject = $_POST["subject"]; $message = $_POST["message"]; $body = "Full Name: $name\n". "E-mail Address: $email\n". "Message: $message"; $header = "From: $email"; mail($to, $subject, $body, $header); $_SESSION['sent'] = "true"; } } webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |