Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJosh Hicks
14,146 PointsHow can I add a "thank you" page after hitting the submit button?
Hello,
I coded an contact form and I am having trouble adding a thank you page after hitting the submit button. I have the action attribute sending it to the correct server, but I don't know how to add a thank you page. Right now it only shows XML data when you hit submit, but the data is still sending. Any Ideas?
Keep in mind: I only know HTML and CSS right now, so any PHP will be over my head, but I can probably get the gist of what you're saying.
6 Answers
Freddy Heppell
9,753 PointsWhich server are you sending it to?
banned banned
Courses Plus Student 11,243 PointsIf you are using php you could just use the header function and set a location. Else you could do it with javascript by using document.location
Tom Mertz
15,254 PointsYou should check out the Building a Simple PHP Application Track and then the 1st stage of the Enhancing a PHP Application Track. By the end of that you'll be able to make a pretty sweet contact form. I think that will be more useful for you than me dumping code here that you might not understand. I was surprised at how cool the PHP stuff turned out.
Tom Mertz
15,254 PointsJust for clarification it goes over the contact form, validation, sending the email, grabbing errors, and setting up a thank you response.
It teaches you other stuff about paypal that you could skip over if you aren't interested.
Jenry Ollivierre
1,987 PointsFrom my knowledge of PHP, here is how to do it. For example, in your contact form action field (<form action="getanswer.php" as an example) and your form method as "post", when you hit the submit button, it will take you to the getanswer.php page. In that page php should be your code to process the form. At the bottom of the code, you can put
header("location: thankyou.php/html") and it would redirect the user to the thankyou.html/php page. On that page, you can simply just put thank you or whatever message you want to put.
Jenry Ollivierre
1,987 PointsI must also add that your webpage will only process php if it have the file saved as a php extension. If you are processing your form on some other extension say .html, you can't add php code in that file as the server will not read it.
Josh Hicks
14,146 PointsI ended up using a hidden redirect field in the html. thanks for all the suggestions though!
Jenry Ollivierre
1,987 PointsOk. You should learn some PHP mate, its a really awesome programming language. I am a novice at it (at least I think so) and I have created some basic blogs by combining it with mysql.
Josh Hicks
14,146 Pointsyeah, it's definitely on my list!!