PHP form takes back to top
<p>I have PHP included a PHP form in my portfolio, that you can see here <a href="http://www.tinybigstudio.com" rel="nofollow">http://www.tinybigstudio.com</a>  The thing is that after SUBMIT, the page goes to TOP instead of staying at the bottom where the form is. </p>

<p>This is the PHP code I have:</p>

<pre><code>&lt;?php
//If the form is submitted
if(isset($_POST['submit'])) {

    //Check to make sure that the name field is not empty
    if(trim($_POST['contactname']) == '') {
        $hasError = true;
    } else {
        $name = trim($_POST['contactname']);
    }



    //Check to make sure sure that a valid email address is submitted
    if(trim($_POST['email']) == '')  {
        $hasError = true;
    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    //Check to make sure comments were entered
    if(trim($_POST['message']) == '') {
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['message']));
        } else {
            $comments = trim($_POST['message']);
        }
    }

    //If there is no error, send the email
    if(!isset($hasError)) {
        $emailTo = 'info@tinybigstudio.com'; //Put your own email address here
        $body = "Name: $name \n\nEmail: $email  \n\nComments:\n $comments";
        $headers = 'From: My Site &lt;'.$emailTo.'&gt;' .$subject = "You have mail, yes!" . "\r\n" . 'Te lo manda: ' . $name;

        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
}
?&gt;
</code></pre>

<p>And this is the form:</p>

<pre><code>&lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" id="contactform"&gt;
                        &lt;fieldset&gt;
                            &lt;label for="name"&gt;Name&lt;/label&gt;
                            &lt;input type="text" size="50" name="contactname" id="contactname" value="" class="required"&gt;

                            &lt;label for="email"&gt;Email&lt;/label&gt;
                            &lt;input type="text" size="50" name="email" id="email" value="" class="required"&gt;

                            &lt;label for="message"&gt;Message&lt;/label&gt;
                            &lt;textarea rows="5" cols="50" name="message" id="message" class="required"&gt;&lt;/textarea&gt;

                        &lt;input type="submit" value="S E N D" class="send" name="submit"  onmouseover="this.className='send_hover';"
                                     onmouseout="this.className='send';"&gt;
                    &lt;/form&gt;



&lt;?php if(isset($hasError)) { //If errors are found ?&gt;
                &lt;p class="error"&gt;Please check if you've filled all the fields with valid information. Thank you.&lt;/p&gt;
            &lt;?php } ?&gt;

            &lt;?php if(isset($emailSent) &amp;&amp; $emailSent == true) { //If email is sent ?&gt;
                &lt;p&gt;&lt;strong&gt;Message Successfully Sent!&lt;/strong&gt;&lt;/p&gt;
                &lt;p&gt;Thank you &lt;strong&gt;&lt;?php echo $name;?&gt;&lt;/strong&gt; for sending a message!&lt;/p&gt;
            &lt;?php }
            ?&gt;
</code></pre>
