wright67uk Posted January 17, 2013 Share Posted January 17, 2013 (edited) Is it possible to redirect a site after a form submission and after 5 seconds? <head> <meta http-equiv="refresh" content="5; URL=asite.htm"> </head> Would surely need to be in the head and before any if statement... and <?php header("refresh: 5; asite.htm"; ?> Would need to be before any output. ie. myform I would like the re-direct to happen 5 seconds after a successful form submission. How do I go about this? <body> <div id="main"> <div id="title">The North London Corporate Cup</div> <div id="subheading"></div> <div id="mid"></div> <div id="form"> <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" onclick="this.value=''" name="name" class="round" value="name" size="20" /> <input type="text" onclick="this.value=''" name="email" class="round" value="email" size="20"/> <input type="submit" class="round" name="Submit" value="Register Your interest"/> </form> </div> <?php if (isset($_POST['Submit'])) { if ($_POST['name'] != "") { $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if (!filter_var($name, FILTER_SANITIZE_STRING)) { $errors .= '* Please enter a valid name.<br/><br/>'; } } else { $errors .= '* Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "* $email is <strong>NOT</strong> a valid email address "; } } else { $errors .= '* Please enter your email address.<br/>'; } if (!$errors) { ### connection here ### if (!$con) { die ('Could not connect: ' . mysql_error ()); } mysql_select_db ("###", $con); mysql_query("INSERT INTO ### (name, email) VALUES ('$name', '$email')"); echo '<p style="color: white; margin-left:105px; font-size:22px; padding-top:15px">* Thankyou, we will be in touch soon!<br></p>'; } else { echo '<p style="color: white; margin-left:105px; padding-top:15px">' . $errors . 'please try again.</p></div>'; } } ?> </div> </body> </html> Edited January 17, 2013 by wright67uk Quote Link to comment https://forums.phpfreaks.com/topic/273264-redirect-after-output/ Share on other sites More sharing options...
kicken Posted January 17, 2013 Share Posted January 17, 2013 Re-structure your page so the PHP code to process the form comes before your HTML, then if the form was submitted successfully output your refresh header and your thank you message. Use variables to hold your messages and then output them later in the proper place in your HTML. Quote Link to comment https://forums.phpfreaks.com/topic/273264-redirect-after-output/#findComment-1406348 Share on other sites More sharing options...
Christian F. Posted January 17, 2013 Share Posted January 17, 2013 Why do you want to wait 5 seconds before redirecting? Quote Link to comment https://forums.phpfreaks.com/topic/273264-redirect-after-output/#findComment-1406363 Share on other sites More sharing options...
wright67uk Posted January 17, 2013 Author Share Posted January 17, 2013 @christian the page would thank the user for their details, giving them 5 seconds to read the message. Before taking them to a different website. @kicken out of interest could I keep the code as it is and place a variable in a html refresh? Populating the variable if the form was successful? Before posting I saw a lot of info on buffering.. and a lot of mixed opinions to go with that info Ps. Thanks for the replies Quote Link to comment https://forums.phpfreaks.com/topic/273264-redirect-after-output/#findComment-1406370 Share on other sites More sharing options...
Christian F. Posted January 17, 2013 Share Posted January 17, 2013 OK, that works. Though, I'd probably redirect users to the 5-sec redirect page. Just to make sure that they don't hit refresh while waiting, and thus resubmits the form accidentally. Quote Link to comment https://forums.phpfreaks.com/topic/273264-redirect-after-output/#findComment-1406371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.