title: PHP Validation to require One of Two Form Fields filled in
body: <p>I am developing a site that uses javascript to handle many functions and PHP based Captcha code to validate the form field.</p>
  
  <p>It works great, but the form will submit if none of the fields are filled in. </p>
  
  <p>I need one of two form fields ['email' or 'phone'] filled in, but neither can be left blank. </p>
  
  <p>The error message can be the same error message thrown up when the captcha field is left blank or filled in incorrectly. </p>
  
  <p>I am new to PHP code and cannot figure out for the life of me how to call the function.</p>
  
  <p>The function code is:</p>
  
  <pre><code> &lt;?php
   if(isset($_POST['send'])){
    $emailFrom = "clientemail.com";
    $emailTo = "clientemail.com";
    $subject = "Contact Form Submission";
  
    $first_name = strip_tags($_POST['first_name']); 
    $last_name = strip_tags($_POST['last_name']); 
    $email = strip_tags($_POST['email']); 
    $phone = strip_tags($_POST['phone']);
    $message = strip_tags(stripslashes($_POST['message'])); 
  
    $body .= "First Name: ".$first_name."\n";
    $body .= "Last Name: ".$last_name."\n";
    $body .= "Email: ".$email."\n";
    $body .= "Phone: ".$phone."\n";
    $body .= "Comments: ".$message."\n";
  
  
    $headers = "From: ".$emailFrom."\n";
    $headers .= "Reply-To:".$email."\n";  
  
    if($_SESSION['security_code'] == $_POST['security_code']){
      $success = mail($emailTo, $subject, $body, $headers);
      if ($success){
      echo '&lt;p class="yay"&gt;Your e&amp;ndash;mail has been sent.&lt;/p&gt;';
      } 
    } else {
      echo '&lt;p class="oops"&gt;Something went wrong. Hit the back button and try again.&lt;/p&gt;';
    }
   } else {
   ?&gt;
  </code></pre>
  
  <p>The form field:</p>
  
  <pre><code>    &lt;form action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;" method="post" id="contact" name="contact"&gt;
  
        &lt;fieldset&gt;
         &lt;label for="name"&gt;&lt;span style="color:#bf252b;"&gt;*&lt;/span&gt;First Name&lt;/label&gt;
         &lt;input type="text" id="first_name" name="first_name"  minlength="2"/&gt;
         &lt;label for="name"&gt;Last Name&lt;/label&gt;
         &lt;input type="text" id="last_name" name="last_name" minlength="2"/&gt;
         &lt;label for="email"&gt;&lt;span style="color:#bf252b;"&gt;*&lt;/span&gt; Email&lt;/label&gt;
         &lt;input type="text" id="email" name="email"   /&gt;
         &lt;label for="phone"&gt;&lt;span style="color:#bf252b;"&gt;*&lt;/span&gt; Phone&lt;/label&gt;
         &lt;input type="text" id="phone" name="phone"  /&gt;
         &lt;label for="message"&gt;Message&lt;/label&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
  
         &lt;textarea id="message" name="message" cols="40" rows="10" &gt;&lt;/textarea&gt;
  
         &lt;img src="../captcha.php" id="captcha" alt="captcha" style="padding:25px 0px 20px 0px;" /&gt;
         &lt;label for="security_code"&gt;Enter captcha&lt;/label&gt;
         &lt;input type="text" id="security_code" name="security_code" autocomplete="off" class="required"/&gt;
  
         &lt;button type="submit" id="send" name="send" style="margin:0px 0px 10px 12px;"&gt;Send!&lt;/button&gt;
  
       &lt;/fieldset&gt;
    &lt;/form&gt; 
  
  &lt;?php } ?&gt; 
  </code></pre>
  
  <p>There is a .php document for running captcha, but am I right in thinking there is a simple solution for this; some extra code in the existing code that will fix my issue? I really want to avoid javascript and plugins if I can help it.</p>
  
  <p>Thanks in advance!!   </p>