title: Save array of inputs with different names to database
body: <p>This is a wordpress plugin.</p>
  
  <p>So I have a hidden input checkbox that gets created when a new item is created.  These items can be turned on/off using sliding toggles (the checkboxes).  After testing by turning some items on/off it looks like the array is being posted when using <code>var_dump($_POST)</code>,</p>
  
  <p>ie: </p>
  
  <pre><code>array (size=3)
    'new_filter' =&gt; string '' (length=0)
    'dp_show_filter_15' =&gt; string 'yes' (length=3)
    'dp_show_filter_16' =&gt; string 'yes' (length=3) 
  </code></pre>
  
  <p>but only when an item is set to yes, no return nothing.</p>
  
  <p>Even though the dump shows the updated array, no values are posted to the database and the input values are empty in Firebug.</p>
  
  <p>Here's my php code:</p>
  
  <pre><code>/*------------------------------------------*/
  /*    Check if the filter is active or not  */
  /*------------------------------------------*/
  
  $settings="select * from wp_dp_settings";
  $filters=$wpdb-&gt;get_results($settings,ARRAY_A);
  
  /*------------------------------------------*/
  /*    We'll use this to save active states  */
  /*------------------------------------------*/
  
  if($_POST){
      ${active}=isset($_POST["dp_show_filter_[$i]"]);
      var_dump($_POST);
      $update="UPDATE wp_dp_settings SET active_filter = '".$active."' WHERE id"; 
      //die( $qry );
      $ok=$wpdb-&gt;query($update);
  
      if($ok==0)
      {
          echo mysql_error();
      }
      else
      { 
          header("Location: admin.php?page=profolio_theme");
          /** Just lettin you know that there was a successful save **/
          echo "&lt;div class='updated settings-error' id='setting-error-settings_updated'&gt; 
          &lt;p&gt;&lt;strong&gt;Active State Saved.&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;";
      }
  }
  
  
  ?&gt;
  &lt;td&gt;&lt;label for="new_filter"&gt;Create a New Filter :&lt;span class="tip"&gt;Must be one word&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="new_filter" id="new_filter"/&gt;&lt;/td&gt;
  &lt;td&gt;
  &lt;/tr&gt;
  &lt;?php $object = new stdClass(); ?&gt;
  &lt;?php foreach( $filters as $key =&gt; $value ) {
      ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;label for="show_filter"&gt;Show &lt;?php echo $object-&gt;$key = $value['filter']; ?&gt; Filter&lt;/label&gt;&lt;/td&gt;        
          &lt;td&gt;&lt;input type="checkbox" id="show_filter_&lt;?php echo $object-&gt;$key = $value['id']; ?&gt;" &lt;?php //if ( $row['active_filter'] === 'yes' ) { ?&gt;checked="checked"&lt;?php //} ?&gt; name="dp_show_filter_&lt;?php echo $object-&gt;$key = $value['id']; ?&gt;" value="&lt;?php echo $object-&gt;$key = $value['active_filter']; ?&gt;"/&gt;&lt;?php echo $object-&gt;$key = $value['active_filter']; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a class="button-primary" href="?page=profolio_theme&amp;del=&lt;?php echo $object-&gt;$key = $value['id'];?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php
      $i++;
  }
  ?&gt;
  </code></pre>
  
  <p>This problem was introduced when I appended the id to the input name, as it used to be <code>name="dp_show_filter"</code> instead of <code>name="dp_show_filter_15"</code> but that cause all items to be updated naturally as I was referencing the input name in my javascript.</p>
  
  <p>You can take a look at that if it helps:</p>
  
  <pre><code>jQuery(document).ready(function(e) {
      var $ = jQuery.noConflict();
  
          $i = 0;
          customCheckbox = $('.dp_wrap input[type="checkbox"]');
          values = [];
  
              return customCheckbox.each(function(i) {
  
                  // the dynamic id
                  var id = parseInt(this.id.replace("show_filter_", ""));
                  var showFilter = $("#show_filter_" + id);
  
                  // the element
                  var el = this;
  
                  // Hide checkbox
                  $(this).hide();
  
                  // Replace element
                  var rep = $('&lt;a href="#"&gt;&lt;span&gt;&lt;/span&gt;&lt;/a&gt;').addClass('dp-checkbox').insertAfter(this);
  
                  // default state
                  if( $(showFilter[i]).val() === 'yes'){
                          $(showFilter).prop('checked', true);
                          $(rep).removeClass('off').addClass('on');
                      } else {
                          $(showFilter).prop('checked', false);
                          $(rep).removeClass('on').addClass('off');
                      }
                  if($(this).is(':checked') ) {
                      $(rep).addClass('on');
                  } else {
                      $(rep).addClass('off');
                  }
  
                  // Click event
                  $(rep).click(function(e) {
  
                      e.preventDefault();
  
                      if( $(el).is(':checked') ) {
  
                          values.push($(showFilter).val('no'), ++$i);
  
                          $(el).prop('checked', false);
                          $(rep).removeClass('on').addClass('off');
                      } else {
  
                          values.push($(showFilter).val('yes'), ++$i);
  
                          $(el).prop('checked', true);
                          $(rep).removeClass('off').addClass('on');
                      }
                  });
              });
  });
  </code></pre>
  
  <p>So when I turn an item on/off, making the checkbox value yes/no, these values should be posted to the database.  Note:  When I switch on/off I notice the values changing to yes/no individually in Firebug, so I know my javascript is working.</p>
  
  <p>Any and all help is greatly appreciated, thanks!</p>