title: HTML Form Submission - Validation - Losing 'buttonType' value
body: <p>I have a form with 2 buttons that both submit. I need to track which button the user clicked to perform different actions. I've added a validation script to one of the buttons to check they have made some selections from the table, but this option appears to remove the button type that the user has selected. It doesn't appear in the POST request data that is processed on form submission.</p>
  
  <p>Here's the buttons and the script that runs for the first button:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("#saveSelected").click(function(e) {
    // put your validation here
    if ($('#selectedAssetIDs').val() == '') {
  
      $("#selectedAssetIDsError").show();
      event.preventDefault();
      return false;
    } else {
      $('#buttonType').val('createSelectedShipments');
      $("form").submit();
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;form class="form-horizontal" id="createShipments" action="createShipments.php" method="post" role="form"&gt;
    &lt;input type="hidden" name="action" value="createStaffShipments"&gt;
    &lt;input type="hidden" name="selectedAssetIDs" id="selectedAssetIDs" value=""&gt;
  
  
    &lt;div class="text-center"&gt;
      &lt;button type="submit" name="buttonType" value="createSelectedShipments" id="saveSelected" class="btn btn-success"&gt;Create Shipments - Selected&lt;/button&gt; &amp;nbsp; &amp;nbsp;
      &lt;button type="submit" name="buttonType" value="createAllShipments" id="saveAll" class="btn btn-success"&gt;Create Shipments - All&lt;/button&gt; &amp;nbsp; &amp;nbsp;
    &lt;/div&gt;
  
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I click the 2nd button it just submits the form and I can see the:</p>
  
  <pre><code>$_POST['buttonType']
  </code></pre>
  
  <p>value in the PHP page it submits to, but when the 1st button is clicked there is no <code>$_POST['buttonType']</code> value.</p>