emerson5000 Posted June 6, 2011 Share Posted June 6, 2011 Using the php form script below, I'd like the script to return the user to the original form page after they submit the form. Thx, Emerson _________________________________ <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']; $headers.=$_GET['phone']. "\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("name@company.com", $subject, " " ."Name: " .$_GET['name']." " ."Phone: " .$_GET['phone']." " ."Email: " .$_GET['email']." " ."Message: " .$_GET['message']." </body> </html>" , $headers); echo ("Your message was sent!"); ?> <script> ___________________________ Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/ Share on other sites More sharing options...
Drummin Posted June 6, 2011 Share Posted June 6, 2011 header("location:mypage.php"); Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226009 Share on other sites More sharing options...
tomtimms Posted June 6, 2011 Share Posted June 6, 2011 You would need to use header('Location: http://www.example.com/');, do you want the redirect after the "Your Message Was Sent" text was seen or do you want to just redirect straight to a page? Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226011 Share on other sites More sharing options...
hemo-ali Posted June 6, 2011 Share Posted June 6, 2011 Or js <form action="" method="" onsubmit="document.location='file.php';"> ......... .......... ............ ............. <input type=submit> </form> Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226014 Share on other sites More sharing options...
ryanfilard Posted June 6, 2011 Share Posted June 6, 2011 header("location:yourpage.php"); it should redirect you. Here is the redirect code in html <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourweb.com/index.html"> Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226023 Share on other sites More sharing options...
emerson5000 Posted June 6, 2011 Author Share Posted June 6, 2011 You would need to use header('Location: http://www.example.com/');, do you want the redirect after the "Your Message Was Sent" text was seen or do you want to just redirect straight to a page? Superfast responses! Thanks to all! tomtimms, Once a user submits the form, I'd like to redirect them to the index page straight away. I'm still doing something incorrectly. I added line 17 shown below but it doesn't redirect. Emerson ________________________________ <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']; $headers.=$_GET['phone']. "\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("myname@company.com", $subject, " " ."Name: " .$_GET['name']." " ."Phone: " .$_GET['phone']." " ."Email: " .$_GET['email']." " ."Message: " .$_GET['message']." header('location: http://www.company.com/index.html'); </body> </html>" , $headers); echo ("Your message was sent!"); ?> <script> ___________________________________ Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226038 Share on other sites More sharing options...
Drummin Posted June 6, 2011 Share Posted June 6, 2011 Looks like you're putting the redirect inside you email message. Put it in place of the "Your messages was sent" line. <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']; $headers.=$_GET['phone']. "\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("myname@company.com", $subject, " " ."Name: " .$_GET['name']." " ."Phone: " .$_GET['phone']." " ."Email: " .$_GET['email']." " ."Message: " .$_GET['message']." </body> </html>" , $headers); header("location: http://www.company.com/index.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226059 Share on other sites More sharing options...
emerson5000 Posted June 6, 2011 Author Share Posted June 6, 2011 Looks like you're putting the redirect inside you email message. Put it in place of the "Your messages was sent" line. <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']; $headers.=$_GET['phone']. "\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("myname@company.com", $subject, " " ."Name: " .$_GET['name']." " ."Phone: " .$_GET['phone']." " ."Email: " .$_GET['email']." " ."Message: " .$_GET['message']." </body> </html>" , $headers); header("location: http://www.company.com/index.html"); ?> Drummin! Rock-star! Works perfectly! Thanks amigo! Quote Link to comment https://forums.phpfreaks.com/topic/238575-simple-php-form-question-how-to-redirect-to-page-after-submit/#findComment-1226076 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.