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

PHP

Contact Form Help

Hello everyone!

I'm working on a contact form on the home page of this website: http://www.ajvelasquez.com/easymailing_lists/ based on the "Adding a Contact Form" PHP course; however, when the form is completed and sent, the "Thank You" message breaks the rotator at the top of the site and also displays the message that was sent.

I'm guessing that the reason this happens is because of the CSS framework that I'm using, since I have the the "Thank You" messaged echoed out once the form is sent, and the form disappears and its replaced with the Thank you message so it breaks the framework.

I just don't know enough PHP to be able to fix this. So if anyone can help me out I would really appreciate it!!

1 Answer

If it's breaking your css have the page redirect to a specified thank you page as shown in the end of the "redirecting after a form submission" video. Your header and footer should stay intact since the body is the only thing that's changing.

Nick thank you for your answer! I don't want to redirect to a thank you page. I would like to keep the visitor on the home page.

No problem, in that case how bout adding a div block that has a "thank you" message in your homepage. Set that div to have conditionals that would show only if the form is submitted and hidden if not. That way you can see if that div breaks your css even before adding the conditionals.

agree with +Nick E. on this one.

usually i just do a simple if..else for this kind of single-page processing script..

if(submitted) {
    // process the form
    // assuming all ok, display the "Thank You" message
} else {
    // display the form
}