title: AJAX not submitting checkbox values to PHP
body: <p>I originally built the form using <a href="http://blog.teamtreehouse.com/create-ajax-contact-form" rel="nofollow">this tutorial</a> but now I need to add a checkbox for signing up to a newsletter. I've tried several fixes I have found already but none seem to be working correctly, and I'm quite new to PHP,AJAX,jQuery. It's been super frustrating :/</p>
  
  <p>Here's the HTML:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="form-messages"&gt;&lt;/div&gt;
  &lt;form class="green-txt" id="ajax-contact" method="post" action="mailer.php"&gt;
     &lt;div class="form-group"&gt;
       &lt;label for="name"&gt;Name:&lt;/label&gt;
       &lt;input type="text" class="form-control" id="name" name="name" placeholder="" required&gt;
     &lt;/div&gt;
     &lt;div class="form-group"&gt;
       &lt;label for="email"&gt;Email:&lt;/label&gt;
       &lt;input type="email" class="form-control email-in" id="email" name="email" placeholder="" required&gt;
     &lt;/div&gt;
     &lt;div class="form-group form-inline"&gt;
       &lt;label for="subscribe"&gt;Subscribe: &lt;/label&gt;
       &lt;input class="sub-btn" type="checkbox" id="subscribe" name="subscribe"&gt;
     &lt;/div&gt;
     &lt;div class="row"&gt;
      &lt;div class="col-xs-6 col-xs-offset-3 col-sm-4 col-sm-offset-8 col-md-4 col-md-offset-8"&gt;
      &lt;button type="submit" class="btn-success btn btn-submit"&gt;Send&lt;/button&gt;
      &lt;/div&gt;
     &lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The js:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
  
  // Get the form.
  var form = $('#ajax-contact');
  
  // Get the messages div.
  var formMessages = $('#form-messages');
  
  // Set up an event listener for the contact form.
  $(form).submit(function(e) {
   // Stop the browser from submitting the form.
   e.preventDefault();
  
   // Serialize the form data.
   var dataString = $(form).serialize();
  
   // Submit the form using AJAX.
   $.ajax({
    type: 'POST',
    url: $(form).attr('action'),
    data: dataString
   })
   .done(function(response) {
    // Make sure that the formMessages div has the 'success' class.
    $(formMessages).removeClass('error');
    $(formMessages).addClass('success');
  
    // Set the message text.
    $(formMessages).text(response);
  
    // Clear the form.
    $('#name').val('');
    $('#email').val('');
  
   })
   .fail(function(data) {
    // Make sure that the formMessages div has the 'error' class.
    $(formMessages).removeClass('success');
    $(formMessages).addClass('error');
  
    // Set the message text.
    if (data.responseText !== '') {
     $(formMessages).text(data.responseText);
    } else {
     $(formMessages).text('Oops! An error occured and your message could not be sent.');
    }
   });
  
  });
  
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>And the PHP:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>// Only process POST reqeusts.
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
      // Get the form fields and remove whitespace.
      $name = strip_tags(trim($_POST["name"]));
     $name = str_replace(array("\r","\n"),array(" "," "),$name);
      $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
      $subscribe = trim($_POST["subscribe"]);
  
  
      // Check that data was sent to the mailer.
      if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
          // Set a 400 (bad request) response code and exit.
          http_response_code(400);
          echo "Oops! There was a problem with your submission. Please complete the form and try again.";
          exit;
      }
  
      // Set the recipient email address.
      // FIXME: Update this to your desired email address.
      $recipient = "";
  
      // Set the email subject.
      $subject = "UP News New Contact - $name";
  
      // Build the email content.
      $email_content = "Name: $name\n";
      $email_content .= "Email: $email\n";
      $subscribe = "Subscribe: $subscribe\n";
  
  
  
      // Build the email headers.
      $email_headers = "From: $name &lt;$email&gt;";
  
      // Send the email.
      if (mail($recipient, $subject, $email_content, $email_headers)) {
          // Set a 200 (okay) response code.
          http_response_code(200);
          echo "Thank You!";
      } else {
          // Set a 500 (internal server error) response code.
          http_response_code(500);
          echo "Oops! Something went wrong and we couldn't send your message.";
      }
  
  } else {
      // Not a POST request, set a 403 (forbidden) response code.
      http_response_code(403);
      echo "There was a problem with your submission, please try again.";
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>What Can I do here to make it process the checkbox data?</p>