title: My form getting submitted twice. Once during onsubmit event and again when bootstrap validator called
body: <p>In the code below you can see I am calling one function on submit of the form, name validate_mainform(). I have checked in my application well even by renaming the function that its calling only once. But if I put an alert the alert showing twice.</p>
  
  <p>After lot of debugging what I found is problem resides in the piece of code below.</p>
  
  <p><strong>Bootstrap_validate.php</strong></p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
      $('#mainForm').bootstrapValidator({
          live: 'enabled',
          fields: {
              reg_date: {
                  group: '.col-sm-3',
                  validators: {
                      notEmpty: {
                          message: 'Please enter the Registration Date'
                      }
                  }
              },
              proj_name: {
                  group: '.col-sm-10',
                  validators: {
                      notEmpty: {
                          message: 'Please enter the Project Name'
                      }
                  }
              }
  
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>If I comment out the above call to bootstrap validator then the function called once.</p>
  
  <p>Below is the code for my form and the function.</p>
  
  <p><strong>project_reg.php</strong></p>
  
  <pre><code>    &lt;form id="mainForm" method="POST" action="" class="form-horizontal" role="form" onsubmit="return validate_mainform();"&gt;
          &lt;div class="form-group text-center"&gt;
                  &lt;input type="submit" value="Submit" class="btn btn-info" name="submit_button" id="btn_submit_id"/&gt;
                  &lt;input type="submit" value="Save" class="btn btn-info" name="save_button" id="btn_save"/&gt;&lt;/br&gt;
                  &lt;br /&gt;
                  &lt;p&gt;&lt;strong&gt;&lt;a href="https://arecontvision.wufoo.com/forms/report-a-problem/" target="_blank"&gt;Report a Problem&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;?php require_once('Bootstrap_validate.php'); ?&gt;
  </code></pre>
  
  <p>Finally my function which is called on submit</p>
  
  <p><strong>validate_mainform()</strong></p>
  
  <pre><code>    function validate_mainform() {
          if ($('#mainForm').length &gt; 0) {
              alert('Here coming twice');
                  if($('input#btn_submit_id').attr('clicked')) {
                      return get_validate_output();
                  } else {
                      return true;
                  }
          } else {
              return get_validate_output();
          }
      }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>I removed validate_mainform call from onsubmit and added onclick of save. Now as you can see inside validate_mainform() I am calling another function get_validate_output(). If the function returns false then I need to prevent form submission . Can you please tell me how to do that?                                                                         </p>
  
  <pre><code> function get_validate_output() {
      var output =  get_result();
      if (output == PRODUCT_VALID.AT_LEAST_ONE) {
          $('.itemidclass').addClass('error-product');
          $('.at-least-one').text('Please Add at Least One Product');
          return false;
      } else if (output == PRODUCT_VALID.ALL_VALID) {
          return false;
      } else {
          if ($('.itemidclass').hasClass('error-product')) {
              $('.itemidclass').removeClass('error-product');
              $('.at-least-one').hide();
          }
          return true;
      }
  } 
  </code></pre>
  
  <p>return false won't work now. As I am calling onclick event now. SO Instead of doing return false what else I can do to prevent form submission.</p>