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

Return to a div on contact form submission.

So I'm working through the Php basics website track with Alena and the media library website.

I'm up to the contact form submission section.

I have the form working as required however when the Php returns an error I'd like it to go to the div the contact form is in.

My contact form is at the bottom of a page. So if when submitted it returns to the top of this page.

1 Answer

You should be able to do something like this

<div id="form-div">
<form method="post" action="yourpage.php#form-div">
<input type="text" name="test">
<input type="submit" value="Submit">
</form>
</div>

When the form is submitted, the page should show the div because of the #form-div id in the form action.

I haven't tested it but I imagine it should work.