ffxpwns Posted April 28, 2012 Share Posted April 28, 2012 I have the website here: http://bossexclusive.com/babyauction/index.php , and http://bossexclusive.com/babyauction/thanks.php . When you press submit on the index.php, it takes you to thanks.php. then, after 5s, it takes you back to index.php. My question is: How could I make it so when I press submit, the box submits the form, but instead of redirecting to thanks.php, it displays the same thank you message on the side, but stays on index.php? If that didn't make sense, let me know. My html and php are below (HTML) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Baby Auction | Discounted Premium Brand Baby Products</title> <link rel="stylesheet" type="text/css" href="styles.css"/> </head> <body> <div id="main"> <div id="contact"> <h1>Sign up to recieve Auction notifications</h1> <form action="emailer.php" method="post"> <input type="text" name="email" id="email" placeholder="yourname@email.com" /> <input type="image" name="submit" src="images/submit.jpg" width="146px" height="20px" value="Submit"> </form> </div> </div> <div class="copyright"> <?php include 'footer.php'; ?> </div> </body> </html> and emailer.php: <?php $email = trim(strip_tags($_POST['email'])); $subject = "Contact form submitted!"; $to = 'BlankingOutMyEmail@gmail.com'; $body = <<<HTML $message HTML; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; mail($to, $subject, $body, $headers); header('Location: thanks.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/ Share on other sites More sharing options...
silkfire Posted April 28, 2012 Share Posted April 28, 2012 <form action="emailer.php" method="post"> That seems to recirect you to another page. Remove that and you'll post to the same page you are on. Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/#findComment-1341448 Share on other sites More sharing options...
ffxpwns Posted April 28, 2012 Author Share Posted April 28, 2012 <form action="emailer.php" method="post"> That seems to recirect you to another page. Remove that and you'll post to the same page you are on. Sure, I can put it on the same page and remove the header('Location: thanks.php');, but how can I put a thankyou note like the one on thanks.php when submit is pressed without leaving the page? Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/#findComment-1341452 Share on other sites More sharing options...
Mahngiel Posted April 29, 2012 Share Posted April 29, 2012 put it in the same conditional as the POST catch. Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/#findComment-1341481 Share on other sites More sharing options...
pwntastic Posted April 29, 2012 Share Posted April 29, 2012 what you can do is make it submit to itself by leaving action blank, inserting your php code at the top of the page where the form is...make sure you add an if() to make sure that it executes when the form is submitted...then under your mail() just echo your thankyou message and then stop the browser with die() after you've echoed out the message Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/#findComment-1341484 Share on other sites More sharing options...
Drummin Posted April 29, 2012 Share Posted April 29, 2012 what you can do is make it submit to itself by leaving action blank, inserting your php code at the top of the page where the form is...make sure you add an if() to make sure that it executes when the form is submitted...then under your mail() just echo your thankyou message and then stop the browser with die() after you've echoed out the message OR, instead of die; just set a variable and within body tag add so the rest of the page loads as it should. Never the less, putting processing above html is a good idea. <?php if (isset($message)){ echo $message; } ?> You can even tie this message into the form so it hides the form. <?php if (isset($message)){ echo $message; }else{ //form goes here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/261777-submit-form-but-stay-on-same-page/#findComment-1341496 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.