title: Ajax submitting form more than once
body: <pre><code>  function form5() {
      var finance = [];
      var paymentmode = "";
      var errors = [];
      if (!$("input[id='payment[]']:checked").length &gt; 0) {
  
        errors = "Please select at least one payment mode.";
  
      }
      if ($("input[id='payment[]']:checked").length &gt; 0) {
        $("input[id='payment[]']:checked").each(function() {
          paymentmode += $(this).val() + ',';
  
        });
      }
  
      var x = _("form4");
      var k;
      if ($("input[id^='i-']").val() == null || $("input[id^='i-']").val() == "") {
  
        errors = "Please fill in all the fields properly .";
  
      }
      if ($("input[id^='i-']").val() == null || $("input[id^='i-']").val() == "") {
  
        errors = "Please fill in all the fields properly .";
  
      }
      if ($("textarea").val() == null || $("textarea").val() == "") {
        errors = "Please fill the cancellation policy ."
  
      }
      /*   for (k = 4; k &lt;= 7; k++) {
                                          var b_val = [];
                                          b_val[k] = x.elements[k];
                                          finance[k-4] = x.elements[k].value;
                                          if (b_val[k].checkValidity() == false) {
  
                                              errors = 'Please ' + b_val[k].placeholder + ' Correctly .';
                                          }
  
                                      }  */
      if ($("input[id='declaration']:checked").length == 0) {
  
        errors = "Please select the declaration to proceed.";
  
      }
      if ($("input[id='terms']:checked").length == 0) {
  
        errors = "Please agree to the terms &amp; conditions to proceed.";
  
      }
  
      if (errors.length &lt;= 0) {
        for (k = 4; k &lt;= 7; k++) {
          var b_val = [];
          b_val[k] = x.elements[k];
          finance[k - 4] = x.elements[k].value;
  
        }
  
        $.ajax({
          type: 'POST',
          url: 'submit.php',
          data: {
            finance: JSON.stringify(finance),
            paymentmode: paymentmode,
            username: username
          },
          success: function(data) {
            $.Notify({
  
              caption: 'finance Details Saved',
              type: 'success',
              timeout: 3000,
              content: data,
              keepOpen: false
            });
            $("button[id='form5']").prop('disabled', true);
            next();
  
          },
  
          error: function() {
            alert('An Error Occured Please try Again');
  
          }
        });
  
      } else {
  
        $.Notify({
          caption: 'Alert',
          type: 'success',
          timeout: 3000,
          content: errors,
          keepOpen: false
  
        });
      }
    }
  
  
  
  &lt;div id="section5" class="container sections "&gt;
    &lt;div class="col-lg-12"&gt;
      &lt;h1 class="main-header"&gt;Finances Details &lt;/h1&gt;
      &lt;label&gt;&lt;a href="Login/logout.php?logout=true"&gt;&lt;i class="glyphicon glyphicon-log-out"&gt;&lt;/i&gt; logout&lt;/a&gt;
      &lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="row main-form"&gt;
      &lt;label&gt;&amp;#2660 Payment Modes :&lt;/label&gt;
      &lt;form id="form4" onsubmit="return false"&gt;
        &lt;div class="payment-mode"&gt;
          &lt;div class="col-md-6 "&gt;
            &lt;label class="input-control checkbox small-check"&gt;
              &lt;input id="payment[]" type="checkbox" value="cash"&gt;
              &lt;span class="check"&gt;&lt;/span&gt;
              &lt;span id="cash" class="caption"&gt;Cash&lt;/span&gt;
            &lt;/label&gt;
            &lt;label class="input-control checkbox small-check"&gt;
              &lt;input id="payment[]" type="checkbox" value="credit-card"&gt;
              &lt;span class="check"&gt;&lt;/span&gt;
              &lt;span id="cc" class="caption"&gt; Credit Card&lt;/span&gt;
            &lt;/label&gt;
            &lt;label class="input-control checkbox small-check"&gt;
              &lt;input id="payment[]" type="checkbox" value="demand-draft"&gt;
              &lt;span class="check"&gt;&lt;/span&gt;
              &lt;span id="dd" class="caption"&gt;Demand Draft&lt;/span&gt;
            &lt;/label&gt;
  
          &lt;/div&gt;
          &lt;div class="col-md-6 "&gt;
            &lt;label class="input-control checkbox small-check"&gt;
              &lt;input id="payment[]" type="checkbox" value="bank-transfer"&gt;
              &lt;span class="check"&gt;&lt;/span&gt;
              &lt;span id="bt" class="caption"&gt;Bank Transfer&lt;/span&gt;
            &lt;/label&gt;
  
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="clearfix"&gt;&lt;/div&gt;
        &lt;label&gt;&amp;#2660 Payment :&lt;/label&gt;
        &lt;div class="payment"&gt;
  
          &lt;div class="col-md-6 "&gt;
            &lt;label&gt;&amp;#2660 Down Payment&lt;/label&gt;
            &lt;div class="input-control select "&gt;
              &lt;span class=" prepend-icon"&gt;Rs.&lt;/span&gt;
              &lt;input id="i-downpayment" type="text " placeholder=" Enter Down Payment"&gt;
  
            &lt;/div&gt;
  
          &lt;/div&gt;
          &lt;div class="col-md-6 "&gt;
            &lt;label&gt;&amp;#2660 Full payment to be made&lt;/label&gt;
            &lt;div class="input-control select "&gt;
              &lt;span class=" prepend-icon"&gt;&lt;/span&gt;
              &lt;input id="i-fullpaydays" type="text " placeholder=" Enter Days"&gt;
              &lt;div class="button-group"&gt;
                &lt;span class="button" disabled&gt;days before the event&lt;/span&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
          &lt;/div&gt;
  
        &lt;/div&gt;
        &lt;div class="clearfix"&gt;&lt;/div&gt;
  
        &lt;div class="col-md-4 "&gt;
          &lt;label&gt;Deposit :&lt;/label&gt;
  
        &lt;/div&gt;
        &lt;div class="col-md-4 "&gt;
          &lt;div class="input-control select "&gt;
            &lt;span class=" prepend-icon"&gt;Rs.&lt;/span&gt;
            &lt;input id="i-deposit" type="number " placeholder=" Enter Deposit Price"&gt;
  
          &lt;/div&gt;
  
        &lt;/div&gt;
        &lt;div class="clearfix"&gt;&lt;/div&gt;
        &lt;div class="col-md-12 col-xs-12"&gt;
          &lt;label class="input-label"&gt;Cancellation Policy :&lt;/label&gt;
          &lt;div class="input-control textarea"&gt;
            &lt;textarea placeholder="Enter the cancellation policy" rows="4" cols="50"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
          &lt;div class="clearfix"&gt;&lt;/div&gt;
          &lt;label class="input-control checkbox small-check"&gt;
            &lt;input id="declaration" placeholder="" type="checkbox" value="1"&gt;
            &lt;span class="check"&gt;&lt;/span&gt;
            &lt;span id="" class="caption"&gt;The above mentioned details are accurate to my best knowledge&lt;/span&gt;
          &lt;/label&gt;
          &lt;div class="clearfix"&gt;&lt;/div&gt;
          &lt;label class="input-control checkbox small-check"&gt;
            &lt;input id="terms" placeholder="" type="checkbox" value="1"&gt;
            &lt;span class="check"&gt;&lt;/span&gt;
            &lt;span id="" class="caption"&gt;I agree to the &lt;a href="terms.html"&gt;terms and conditions&lt;/a&gt;&lt;/span&gt;
          &lt;/label&gt;
        &lt;/div&gt;
        &lt;div class="clearfix"&gt;&lt;/div&gt;
  
        &lt;div style="padding-top:5em;" class="col-md-12 col-md-offset-4"&gt;
          &lt;button onclick="form5()" name="" class="button success"&gt;Submit&lt;/button&gt;
  
        &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Can anyone help me , I see two entries in the database. I have checked the back-end PHP .seems fine. Please check the code above .
  Any help would be great .
  I am debugging from my end but I need a quick help .Which may be helpful .</p>