Scroll down to contact form at bottom of page when form is submitted with errors

Viewed 7156

What I'm trying to accomplish is when a user tries to submit the form with errors and the error messages are added/page reloads I need the page to automatically scroll down to the bottom of the page to the contact form location.

I currently have the form within my footer.php and I'm including it in on each page like this: <?php include('includes/footer.php') ?>

here is my html for the form:

<form method="post" action="#">
  <input name="name" placeholder="Name*" type="text" value="<?php echo htmlspecialchars($name);?>">
     <span class="error"><?php echo $nameErr;?></span>

  <input name="email" placeholder="Email*" type="email" value="<?php echo htmlspecialchars($email);?>">
    <span class="error"><?php echo $emailErr;?></span>

  <input name="phone" placeholder="Phone #" type="tel" />

  <textarea name="message" placeholder="Message*"><?php echo $message;?></textarea>
    <span class="error"><?php echo $messageErr;?></span>

  <input id="submit" type="submit" name="submit" value="Send" />
</form>


EDIT - Based on the answer below this is what fixed my problem...

<form method="post" action="#footer">
  //everything here
</form>
2 Answers
Related