title: PHP Notice: Undefined index: when syncing form submission to mailchimp list
body: <p>I have developed a wordpress plugin which is a form builder. The plugin allows users to enter a list ID, API ID, First Name, Last name and Email address variable in order to sync form submissions to a chosen mailchimp list when the form is submitted.</p>
  
  <p>I have had this working but recently noticed it is no longer sending info to mailchimp.</p>
  
  <p>Checking over my debug file, I am getting the following errors:</p>
  
  <pre><code>[03-Mar-2017 11:53:47 UTC] PHP Notice:  Undefined index: emailId in .../plugins/layers-form-builder/includes/class-send-form.php on line 37
  [03-Mar-2017 11:53:47 UTC] PHP Notice:  Undefined index: emailSubject in .../plugins/layers-form-builder/includes/class-send-form.php on line 38
  [03-Mar-2017 11:53:47 UTC] PHP Notice:  Undefined index: mcListID in .../plugins/layers-form-builder/includes/class-send-form.php on line 41
  [03-Mar-2017 11:53:47 UTC] PHP Notice:  Undefined index: mcAPIkey in .../plugins/layers-form-builder/includes/class-send-form.php on line 42
  [03-Mar-2017 11:53:47 UTC] PHP Notice:  Undefined index: formData in .../plugins/layers-form-builder/includes/class-send-form.php on line 54
  </code></pre>
  
  <p>Here is the script that triggers when the form is submitted, this handles the data via ajax:</p>
  
  <pre><code>&lt;script&gt;
  jQuery(document).ready(function($) {
      $('#layers-widget-form_builder-17 .builderForm').each(function() {
          $(this).on("submit", function(event) {
              event.preventDefault();
              var formData = $(this).serialize();
              var emailId ='sam.skirrow@gmail.com';
              var emailSubject ='New website form submission';
              var mcListID ='2d2fbcd34d';
              var mcAPIkey ='7f306818ee8b588162a7be1ac72d213b-us10';
                                  var mcEmail = $(this).find('input[name="email"]').val(); 
                                                  var mcLname = $(this).find('input[name="last_name"]').val();
                                                  var mcFname = $(this).find('input[name="first_name"]').val(); 
                              var mcForm = $(this);
  
              $('#layers-widget-form_builder-17 .builderForm').addClass('loading');
              $.ajax({
                      type        : 'POST', // define the type of HTTP verb we want to use (POST for our form)
                      url         : 'http://thedistractionsband.co.uk/wp-content/plugins/layers-form-builder/includes/class-send-form.php', // the url where we want to POST
                      data        : {'formData' :formData,'emailId':emailId, 'emailSubject':emailSubject, 'mcListID':mcListID, 'mcAPIkey':mcAPIkey, 'mcEmail':mcEmail, 'mcFname':mcFname,  'mcLname':mcLname}, // our data object
                      dataType    : 'json', // what type of data do we expect back from the server
                      encode      : true
                  })
                  .done(function(data) {
                      // log data to the console so we can see
                      console.log(data); 
                      //setTimeout(function(){$('#overlay').hide();}, 4000);
                      //$('#overlay').remove();
                      $('.successMsg').html('&lt;i class="fa fa-check"&gt;&lt;/i&gt; Your message has been sent!');
                      $('.form-builder-submit').hide();
                      setTimeout(function(){
                          $('.successMsg').hide();
                          $('.builderForm').removeClass('loading');
                          $('.form-builder-submit').show();}, 3000);
                      // Reset form after submission
                      $(".builderForm")[0].reset();
                  })
                  .fail(function (jqXHR, textStatus) {
                      console.log(textStatus);
                      $('.successMsg').html('&lt;i class="fa fa-cross"&gt;&lt;/i&gt; Oops, there seems to have been an error when submitting the form');
                      setTimeout(function(){$('.successMsg').hide();}, 3000);
                  });
  
              event.preventDefault();
  
  
  
  
          });
      });
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is the contents of class-send-form.php (the file with the errors)</p>
  
  <pre><code>&lt;?php
  /* Layers Form Builder Plugin
   * Script to send custom form 
   */
  require_once('../../../../wp-load.php');
  
  // function to send data to mailchimp
  function rudr_mailchimp_subscriber_status( $email, $status, $list_id, $api_key, $merge_fields = array('FNAME' =&gt; '','LNAME' =&gt; '') ){
  $data = array(
      'apikey'        =&gt; $api_key,
      'email_address' =&gt; $email,
      'status'        =&gt; $status,
      'merge_fields'  =&gt; $merge_fields
  );
  $mch_api = curl_init(); // initialize cURL connection
  
  curl_setopt($mch_api, CURLOPT_URL, 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($data['email_address'])));
  curl_setopt($mch_api, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$api_key )));
  curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
  curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true); // return the API response
  curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'PUT'); // method PUT
  curl_setopt($mch_api, CURLOPT_TIMEOUT, 10);
  curl_setopt($mch_api, CURLOPT_POST, true);
  curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
  
      $result = curl_exec($mch_api);
      return $result;
  }
  
  function getIfSet(&amp;$value, $default = '')
  {
      return isset($value) ? $value : $default;
  }
  
  //$layers_email_address = Layers_Form_Builder_Widget::send_to_email(); 
  $layers_email_address = $_REQUEST['emailId'];
  $layers_email_subject = $_REQUEST['emailSubject'];
  
  // mailchimp vars
  $mc_list_id = $_REQUEST['mcListID'];
  $mc_api_key = $_REQUEST['mcAPIkey'];
  $mc_email = getIfSet($_REQUEST['mcEmail']); 
  $mc_fname = getIfSet($_REQUEST['mcFname']); 
  $mc_lname = getIfSet($_REQUEST['mcLname']); 
  
  // if there are any errors in our errors array, return a success boolean of false
  if (!empty($errors)) {
  // if there are items in our errors array, return those errors
      $data['success'] = false;
      $data['errors'] = $errors;
  
  } else {
  parse_str($_REQUEST['formData'], $formFields);
  $html='&lt;html&gt;&lt;body&gt;';
  foreach ($formFields as $key =&gt; $value) {
      $html .= '&lt;p&gt;&lt;label&gt;' . $key . ' :&lt;/label&gt; ' . $value . '&lt;/p&gt;';
  }
  $html .='&lt;/body&gt;&lt;/html&gt;';
  $to = $layers_email_address;
  $subject = $layers_email_subject;
  $txt = $html;
  $headers = "From: &lt;".$to."&gt;". "\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1"."\r\n";
  wp_mail($to,$subject,$txt,$headers);
  
  //mailchimp test
  $email = $mc_email;
  $status = 'subscribed'; // "subscribed" or "unsubscribed" or "cleaned" or "pending"
  $list_id = $mc_list_id; // where to get it read above
  $api_key = $mc_api_key; // where to get it read above
  $merge_fields = array('FNAME' =&gt; $mc_fname,'LNAME' =&gt; $mc_lname);
  
  rudr_mailchimp_subscriber_status($email, $status, $list_id, $api_key, $merge_fields );    
  
  // if there are no errors process our form, then return a message
  
  // show a message of success and provide a true success variable
  $data['success'] = true;
  $data['message'] = 'Success!';
  }
  
  // return all our data to an AJAX call
  echo json_encode($data);
  </code></pre>
  
  <p>My issue seems to reside around these lines:</p>
  
  <pre><code>$layers_email_address = $_REQUEST['emailId'];
  $layers_email_subject = $_REQUEST['emailSubject'];
  
  // mailchimp vars
  $mc_list_id = $_REQUEST['mcListID'];
  $mc_api_key = $_REQUEST['mcAPIkey'];
  $mc_email = getIfSet($_REQUEST['mcEmail']); 
  $mc_fname = getIfSet($_REQUEST['mcFname']); 
  $mc_lname = getIfSet($_REQUEST['mcLname']);
  </code></pre>
  
  <p>However I'm unsure as to how I should test this/debug this issue, any help would be much appreciated and I can add more code snippets if required.</p>