title: validating and submitting with 'if' and 'else' using PHP
body: <p>This code is supposed to check to see if any fields are blank or invalid, if they are, it will turn them red. if all is ok then it will send to the database.   </p>
  
  <p>The problem is, if the last 'if' is not met, then the 'else' will fire.<br>
  This means as long as a valid email address is entered the form will submit, even if other fields are blank.  </p>
  
  <p>How can I make so that all requirements must be met for the form to submit </p>
  
  <pre><code>if(empty($_POST['company'])) {
    echo '&lt;script type="text/javascript"&gt;
      $(document).ready(function() { 
      $("#companyForm").animate({backgroundColor:"#ffbfbf"},500);
      });
      &lt;/script&gt;
    ';
  }
  if(empty($_POST['name'])) {
    echo '&lt;script type="text/javascript"&gt;
      $(document).ready(function() { 
      $("#nameForm").animate({backgroundColor:"#ffbfbf"},500);
      });
      &lt;/script&gt;
    ';
  }
  if(empty($_POST['email'])) {
    echo '&lt;script type="text/javascript"&gt;
      $(document).ready(function() { 
      $("#emailForm").animate({backgroundColor:"#ffbfbf"},500);
      });
      &lt;/script&gt;
    ';
  }
  if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE){
    echo '&lt;script type="text/javascript"&gt;
      $(document).ready(function() { 
      $("#emailForm").animate({backgroundColor:"#ffbfbf"},500);
      });
      &lt;/script&gt;
    ';
  }
  else { 
    //submits to database... 
  }
  </code></pre>