title: PHP Contact Form Submission (Honey Pot)
body: <p>New to PHP hence the very basic question. I'm trying to create a contact form that has a Honey Pot attribute built in. I want to check this honey pot value in both JS and PHP before submission. </p>
  
  <p>Cases:</p>
  
  <ul>
  <li>If no fields are filled out JS error don't Submit</li>
  <li>If all fields are filled out BUT Honey Pot, Pass through JS, POST to PHP and send email</li>
  <li>If all fields are filled out fail on JS and don't POST, HOWEVER I would like this to also be applicable to the PHP even if it's redundant just to understand PHP better. </li>
  </ul>
  
  <p>Problem:</p>
  
  <p>The JS validation is fine and I check <code>.val</code> of the input field. However I cannot seem to get the same validation in PHP to work. </p>
  
  <p><strong>index.html (contact form) *using jQuery Validate:</strong></p>
  
  <pre><code>&lt;form id="contactForm" method="GET" action="" class="contact-form" novalidate="novalidate"&gt;
    &lt;div class="input-field col s12"&gt;
      &lt;input name="name" type="text" id="name" class="validate" required/&gt;
      &lt;label for="name"&gt;Name&lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="input-field col s12"&gt;
      &lt;input name="email" type="text" id="email" class="validate" required/&gt;
      &lt;label for="email"&gt;E-mail&lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="input-field col s12"&gt;
      &lt;textarea name="message" id="message" class="materialize-textarea" required&gt;&lt;/textarea&gt;
      &lt;label&gt;Message&lt;/label&gt;
     &lt;/div&gt;
     &lt;div class="input-field comment col s12"&gt;
       &lt;label&gt;If you're human leave this blank:&lt;/label&gt;
       &lt;input name="comment" type="text" id="comment" class="form-comment" /&gt;
     &lt;/div&gt;
     &lt;div class="col s12"&gt;
       &lt;button class="btn button-primary contact-submit-button waves-effect waves-light" type="submit"&gt;Send&lt;/button&gt;
     &lt;/div&gt;
     &lt;div id="form-result"&gt;&lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p><strong>contact-form.js</strong></p>
  
  <pre><code>$(document).ready(function () {
    var contactFormResult = $('#form-result');
    var contactForm = $('#contactForm');
    contactFormResult.hide();
    $.validator.setDefaults({
      submitHandler: function () {
        var nameValue = $('#name').val();
        var emailValue = $('#email').val();
        var messageValue = $('#message').val();
        var robotValue = $('#comment').val();
        console.log('contact form submission, name value: ' + nameValue, ' email value: ' + emailValue + ' message value: ' + messageValue + ' robot value: ' + robotValue);
  
        // 
        // I want this to pass through JS and FAIL in PHP
        //
        if (robotValue = ''){
          contactFormResult.text('you are a robot').fadeIn();
          return false;
        } else {
           $.ajax({
            type: "POST",
            url: "contactSubmission.php",
            data: {
              name: nameValue,
              email: emailValue,
              message: messageValue,
              robotTest: robotValue
            }
          }).done(function () {
            contactForm.find("input[type=text], input[type=email], textarea").val("");
            contactFormResult.text('form submitted successfully').fadeIn();
          });
        }
      }
    });
    contactForm.validate();
  });
  </code></pre>
  
  <p><strong>contactSubmission.php</strong></p>
  
  <pre><code>&lt;?php
  if ($_POST){
      //Sanitize input data using PHP filter_var().
      $nameValue = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
      $emailValue = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
      $messageValue = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
      $robotValue = filter_var($_POST["robotTest"], FILTER_SANITIZE_STRING);
  
      if(!empty($robotValue){
          die();
      } else {
          $to = 'myemail@gmail.com';
          $subject = 'Subject Line';
  
          $message = 'Name: ' .$nameValue. ' Email: ' .$emailValue.' Message: '.$messageValue;
  
          mail($to, $subject, $message);
      }
  }
  ?&gt;
  </code></pre>