When I submit button without any information I got this error message: "Please check if you've filled all the fields with valid information. Thank you." While every input text has to have this text "This field is required." below instead of just one message for the whole form. In the same time form works when the information was submitted.

Thank you
Ben






<?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 that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}

//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 = 'vandreyuk@gmail.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>


<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Keywords" content="Vkreative studio, portfolio" />
<meta name="Description" content="Web, Print, Mobile device Design, html, css, xhtml, javascript, jquery, cascading style sheets" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27955373-1']);
_gaq.push(['_trackPageview']); (function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<link rel="stylesheet" type="text/css" href="main_style.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<!--Collapsable Menu-->
<script src="clbsmenu/jquery-1.2.1.min.js" type="text/javascript"></script>
<script src="clbsmenu/menu-collapsed.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="clbsmenu/style.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript">
<script src="jquery.validate.pack.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function(){
$("#contactform").validate();
});
</script>

<style type="text/css">

body {
font-family:Arial, Tahoma, sans-serif;
}
#contact-wrapper {
width:430px;
margin-top: 158px;
margin-left: 340px;
color:white;
font-size: 12px;
}
#contact-wrapper div {
clear:both;
margin:1em 0;
}
#contact-wrapper label {
display:block;
float:none;
width:auto;
}
form#contactform input {
border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
border-style:solid;
border-width:1px;
padding:5px;
font-size:17px;

}
form#contactform textarea {
font-family:Arial, Tahoma, Helvetica, sans-serif;
font-size:100%;
margin: 0px 0px;
height:120px;
border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
border-style:solid;
border-width:1px;
}
.submitbutton {
margin-left:248px;
width:150px;
border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
border-style:solid;
border-width:1px;
font-size:16px;
color:white;
background-color: black;
font-size: 17px;

}
.submitbutton:hover {
background-color: #666;
}

}
.submitbutton:hover {
background-color: #666;
}

#contactname {
width:385px;
}

#email {
width:385px;
}

#subject {
width:385px;
}
#message {
width:395px;
}
</style>

<title>Contact</title>
</head>
<body>


<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="container">
<div id="header"></div><!-- end header -->
<div id="mid">
<div id="navplace">
<div class="h_mnu_01">
<ul>
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="about.html">About</a>
</li>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li>
<a href="contact.html">Contact</a>
</li>
</ul>
</div>
</div>
<div class="sidebar1">
<!-- end .sidebar1 -->
<p class="touch">get in touch</p>
<div id="emailbox"><!-- .emailbox -->
<p class="touch2"><i>Send me a message or just say hello, I will get back to you ASAP.</i></p>

</div>
<p class="touch3">contact me</p>
<div id="social">
<div id="mail"><img src="images/mail.png"><p class="mail">vandreyuk@gmail.com</p></div> <br /><br />
<div id="phone"><img src="images/phone.png"><p class="phone">(760)&nbsp;471-2676</p></div>
</div>
</div>



<div id="contact-wrapper">
<?php if(isset($hasError)) { //If errors are found ?>
<p class="error">Please check if you've filled all the fields with valid information. Thank you.</p>
<?php } ?>

<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<p><strong>Email Successfully Sent!</strong></p>
<p>Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
<?php } ?>


<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<div>
<label for="name"><strong>Name:</strong></label>
<input type="text" size="50" name="contactname" id="contactname" value="" class="required" />
</div>

<div>
<label for="email"><strong>Email:</strong></label>
<input type="text" size="50" name="email" id="email" value="" class="required email" />
</div>

<div>
<label for="subject"><strong>Subject:</strong></label>
<input type="text" size="50" name="subject" id="subject" value="" class="required" />
</div>

<div>
<label for="message"><strong>Message:</strong></label>
<textarea rows="5" cols="50" name="message" id="message" class="required"></textarea>
</div>
<input type="submit" class="submitbutton" value="Send Message" name="submit" />
</form>
</div>
</div><!-- mid end -->
<div class="footer">
<div id="access">
<!--access-->
<a title="Twitter" href="https://twitter.com/#!/VkreativeS" target="_blank"><img class="icon_social" src="images/icon_twitter-trans.png" alt="Twitter" /></a>&nbsp;&nbsp;&nbsp; <a title="LinkedIn" href="http://www.linkedin.com/pub/veniamin-andreyuk/11/825/b02" target="_blank"><img class="icon_social" src="images/icon_linkedin-trans.png" alt="LinkedIn" /></a>&nbsp;&nbsp;
<a title="Facebook" href="https://www.facebook.com/profile.php?id=100003376785103" target="_blank"><img class="icon_social" src="images/icon_facebook-trans.png" alt="Facebook" /></a>&nbsp;&nbsp;&nbsp;
<div id="like" div class="fb-like" data-href="http://www.vkreativestudio.com/" data-send="true" data-layout="button_count" data-width="0" data-height="0" data-show-faces="true"></div>
</div><!--access end-->

<p class="copyright">
<!--copyright-->
Copyright &#169; 2013 Vkreative Studio. All rights reserved.

</p><!--copyright end-->
</div><!-- end .footer -->
</div>
<!-- end .container -->
</body>
</html>