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!

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 trial

General Discussion

How can I add a "thank you" page after hitting the submit button?


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
Freddy Heppell
9,753 Points

Which server are you sending it to?

If 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
Tom Mertz
15,254 Points

You 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
Tom Mertz
15,254 Points

Just 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.

From 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.

I 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.

I ended up using a hidden redirect field in the html. thanks for all the suggestions though!

Ok. 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.

yeah, it's definitely on my list!!