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 trial
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsPhp contact script
I have created a contact script using php and want to hook it on to handle the form sending process in html. However l don't want to created a new page to say thank when forms are sent as an abit lazy. So wanted to send users back to the home page after they sent the form.l wanted to keep the file seperate as html and php. Confused as to how to handle the whole thing. A quick narration would be greate please. Thanks
1 Answer
eck
43,038 PointsIf you want a PHP solution, all you need to do is, at the end of you contact script, run the PHP header function. This will allow you to redirect the user to the page of your choice. There is an important detail that I will reference from the link above: "header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP" otherwise you get an error.
There is also a JavaScript solution that you may want to consider. Using Ajax with JS you can submit your form info to your contact script without directing the user to a new page and avoid a page refresh. If you are interested in that, you can learn how to use Ajax here.
Hope that helps!