title: Php Contact Form - Optional Fields (trim)
body: <p>I have a php contact form I'm trying to edit to suit my needs. Currently, every field needs to be filled out in order for the form to work. What do I need to edit in order to make some fields optional? Below isn't the full script, but I have a feeling its the segment of the field most important for what I need to do.</p>
  
  <p>Thanks</p>
  
  <pre><code>$name    = $_POST['name'];
  $email  = $_POST['email'];
  $phone  = $_POST['phone'];
  $date    = $_POST['date'];
  $guests  = $_POST['guests'];
  $subject  = $_POST['subject'];
  $comments = $_POST['comments'];
  
  if (isset($_POST['verify'])) : 
      $posted_verify   = $_POST['verify']; 
      $posted_verify   = md5($posted_verify); 
  else :
      $posted_verify = '';
  endif;
  
  // Important Variables
  $session_verify = $_SESSION['verify'];
  
  if (empty($session_verify)) $session_verify = $_COOKIE['verify'];
  
  $error = '';
  
      if(trim($name) == '') {
          $error .= '&lt;li&gt;Your name is required.&lt;/li&gt;';
      }
  
      if(trim($date) == '') {
          $error .= '&lt;li&gt;Your event date is required.&lt;/li&gt;';
      }
  
      if(trim($email) == '') {
          $error .= '&lt;li&gt;Your e-mail address is required.&lt;/li&gt;';
      } elseif(!isEmail($email)) {
          $error .= '&lt;li&gt;You have entered an invalid e-mail address.&lt;/li&gt;';
      }
  
      if(trim($phone) == '') {
          $error .= '&lt;li&gt;Your phone number is required.&lt;/li&gt;';
      } elseif(!is_numeric($phone)) {
          $error .= '&lt;li&gt;Your phone number can only contain digits.&lt;/li&gt;';
      }
  
  
      if(trim($comments) == '') {
          $error .= '&lt;li&gt;You must enter a message to send.&lt;/li&gt;';
      }
  
      if(trim($guests) == '') {
          $error .= '&lt;li&gt;The number of guests is required.&lt;/li&gt;';
      } elseif(!is_numeric($guests)) {
          $error .= '&lt;li&gt;Your phone number can only contain digits.&lt;/li&gt;';
      }
  </code></pre>