title: Sending multiple forms data through jQuery Ajax
body: <p>I have two forms for which I want to send the data through jQuery Ajax call. I managed to send it successfully for one form but I am not able to send the data from both of them through the same Ajax call.</p>
  
  <p>My forms are:</p>
  
  <pre><code>&lt;form id="filter-group1"  method="post" name="filtergroup1"&gt;
  &lt;input type="checkbox" name="colour1" value="Value1" onclick="filterBy()" /&gt;&lt;label&gt;Option 1&lt;/label&gt;
  &lt;input type="checkbox" name="colour2" value="Value2" onclick="filterBy()" /&gt;&lt;label&gt;Option 2&lt;/label&gt;
  &lt;input type="checkbox" name="colour3" value="Value3" onclick="filterBy()" /&gt;&lt;label&gt;Option 3&lt;/label&gt;
  &lt;/form&gt;
  &lt;form id="filter-group2" method="post" name="filtergroup2"&gt;
  &lt;input type="checkbox" name="size1" value="Value1" onclick="filterBy()" /&gt;&lt;label&gt;Option 1&lt;/label&gt;
  &lt;input type="checkbox" name="size2" value="Value2" onclick="filterBy()" /&gt;&lt;label&gt;Option 2&lt;/label&gt;
  &lt;input type="checkbox" name="size3" value="Value3" onclick="filterBy()" /&gt;&lt;label&gt;Option 3&lt;/label&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And the function is:</p>
  
  <pre><code>function filterBy() { 
      var fgroup1 = document.filtergroup1;
      var fgroup2 = document.filtergroup2;
      var dataString1 = $(fgroup1).serialize();
      var dataString2 = $(fgroup2).serialize();
      var filterdata = [];
      filterdata.push(dataString1,dataString2);
      $.ajax( {
          type: 'POST',
          url: 'filter.php',
          data: filterdata,
          success: function(data) {
              console.log(data);
              $('#message').html(data);
          }
      });
  }
  </code></pre>
  
  <p>I have this in the php file:</p>
  
  <pre><code>echo var_export($_POST);
  </code></pre>
  
  <p>The function works fine for one form if I replace data: with</p>
  
  <pre><code>data: dataString1,
  </code></pre>
  
  <p>I am trying to achieve the same result with the data from both forms but I don't want to use a different function for each form. </p>
  
  <p>I appreciate any help. Thank you.</p>