title: PHP Post Parameter Passing Validation When the Value is Empty
body: <p>I'm having an issue when the posting a selection value for server side validation. When the user does not make a selection, therefore it is still selected on "Select...". It still passes the empty() method, although the value is empty.</p>
  
  <pre><code>&lt;?php
  
  // Email Properties
  $email_to = "user@domain.com";
  $email_subject = "3DMark3t Contact:";
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];
  $comments = $_POST['comments'];
  $select = $_POST['select'];
  
  function formError($error) {
      // your error code can go here
      echo "We are very sorry, but there were error(s) found with the form you submitted. ";
      echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;";
      echo $error."&lt;br /&gt;&lt;br /&gt;";
      echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
      die();
  }
  
  // Make sure all fields are not empty
  if(empty($first_name) || empty($last_name) || empty($email) ||
      empty(telephone) || empty($comments) || empty($select)) {
      // Return error
      formError('Please fill in all of the fields.');       
  }
  
  // Regex Tests
  $error_message = "";
  
  // Expressions
  $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  $string_exp = "/^[A-Za-z .'-]+$/";
  
  if(!preg_match($email_exp, $email_from)) {
      $error_message .= 'The Email Address you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(!preg_match($string_exp, $first_name)) {
      $error_message .= 'The First Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(!preg_match($string_exp, $last_name)) {
      $error_message .= 'The Last Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(!empty($error_message)) {
      formError($error_message);
  }
  
  $email_message = "3DMark3t Contact: \n";
  $email_message .= "First Name: {$first_name} \n";
  $email_message .= "Last Name: {$last_name} \n";
  $email_message .= "Email: {$email} \n";
  $email_message .= "Telephone: {$telephone} \n";
  $email_message .= "Select One: {$select} \n";
  $email_message .= "Comments: {$comments} \n";
  
  // Create email headers
  $headers = 'From: '.$email_from."\r\n".
  'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  @mail($email_to, $email_subject, $email_message, $headers);  
  
  header("Location /");
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form name="htmlform" method="post" action="php/html_form_send.php"&gt;
      &lt;table width="450px"&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="first_name"&gt;First Name *&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;input  type="text" name="first_name" maxlength="30" size="30"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="last_name"&gt;Last Name *&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;input  type="text" name="last_name" maxlength="30" size="30"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="email"&gt;Email Address *&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;input  type="text" name="email" maxlength="30" size="30"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="telephone"&gt;Telephone Number&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;input  type="text" name="telephone" maxlength="30" size="30"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="select"&gt;Select One *&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;select name="select"&gt;
                      &lt;option value=""&gt;Select...&lt;/option&gt;
                      &lt;option value="3DModels"&gt;3DModels&lt;/option&gt;
                      &lt;option value="Graphic Design"&gt;Graphic Design&lt;/option&gt;
                      &lt;option value="Web Design"&gt;Web Design&lt;/option&gt;
                      &lt;option value="Tutorials"&gt;Tutorials&lt;/option&gt;
                      &lt;option value="Report"&gt;Report&lt;/option&gt;
                      &lt;option value="Requests"&gt;Requests&lt;/option&gt;
                  &lt;/select&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;label for="comments"&gt;Comments *&lt;/label&gt;
              &lt;/td&gt;
              &lt;td valign="top"&gt;
                  &lt;textarea  name="comments" maxlength="1000" cols="32.5" rows="6"&gt;&lt;/textarea&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2" style="text-align:center"&gt;
               &lt;input type="submit" value="Submit"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>