Hello folks. I need some PHP help..obviously. I attempted to use my own logic to resolve the issue but that of course didn't work. Basically, I needed to add captcha validation which I did using "recaptcha" plugin. While it works, it's a very clumsy implementation of it, if I may say that. The code is below.

So right now, when you fill out the form correctly on the first go, including the captcha text, it submits no problem. But say you miss a field and when you get to the captcha validation, you input the right text and hit submit. As expected, once it validates the text, it brings up the "Missing Field!" error. You go back and make appropriate changes but when you hit submit this time, the captcha validation fails and you have to refresh the image and re-submit. It makes sense why this occurs, but it's extremely annoying.

I was hoping someone could be kind enough to modify the code or perhaps guide on how I can make it so that the captcha validation happens at the very end. Meaning, if there is a blank form and someone hits submit, it should say "Missing Fields!" or "Sorry. Not a valid Email!", basically going through the entire form validation process before it gets to the captcha validation.

I've been playing around with the "if" statement all day and I can't seem to find a resource online. Any help would be appreciated.

Contact Page: http://khangp.com/#contact

PHP Code:
    <link rel="stylesheet" type="text/css" href="css/styles.css" />

$privatekey "6LdedO4SAAAAAJiL3Lfa-c_GpT4W5Ij9M9ZGKen-";
$resp recaptcha_check_answer ($privatekey,

      if (!
$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly.\n<br /> Go back and try it again." .
"\n<br />(reCAPTCHA said: " $resp->error ")");
  } else {
// Your code here to handle a successful verification

function validateEmail($value){
if ( isset($_POST['name']) && $_POST['name']!="Name" && isset($_POST['email']) && $_POST['email']!="Email" && isset($_POST['subjectSelect']) && $_POST['subjectSelect']!="" && isset($_POST['message']) && $_POST['message']!="Your comments..." ) {
if ( validateEmail($_POST['email']) ) {
////////////////////// EDIT HERE  /////////////////////////

$mailMessage utf8_decode($mailMessage);
////////////////////// END EDIT  /////////////////////////
            //SENDER EMAIL
$mailHeader=$mailHeader."Mime-Version: 1.0\n"
$mailHeader=$mailHeader."Content-Type: text/html";
            if ( 
mail($destination,$subject,$mailMessage,$mailHeader) ) {
'<span class="output">Message successfully sent!<br />We will contact you shortly.<br /> Thank you!</span>';
            else echo 
'<span class="outputred">Server error. Please, try again later</span>';
        else echo 
'<span class="outputred">Sorry. Not a valid Email!</span>';    //EMAIL VALIDATION ERROR
    else echo 
'<span class="outputred">Missing fields!</span>';        //VARS ERROR