Keeping Bootstrap modal open after form submission

Keeping Bootstrap modal open after form submission

I have a form in a Bootstrap 4 modal and am trying to replace this modal form with a thank you message within the same modal, but the modal keeps closing after the submit button is clicked. I tried the following, but it's not working.

  1. <button type="submit" class="btn btn-primary" onclick="$('#formModal').modal({'backdrop': 'static'});" >Submit</button>

The goal is to submit the data to our db when the submit button is clicked and then hide the form and display a thank you within the same modal. Here's the basics of the code for the modal:

  1. <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel" aria-hidden="true">
  2.   <div class="modal-dialog" role="document">
  3.     <div class="modal-content">
  4.       <div class="modal-header">
  5.         <h5 class="modal-title" id="formModalLabel">Client Add Form</h5>
  6.         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  7.           <span aria-hidden="true">×</span>
  8.         </button>
  9.       </div>
  10.       <div class="modal-body showform" id="formBody">
  11.         <iframe name="formSubmitFrame" id="formSubmitFrame" style="display:none;" width="0" height="0"></iframe>
  12.         <form action="xxxxxxxxxxxxxxxx" method="post" target="formSubmitFrame" class="needs-validation" role="form" id="form">
  13.           <fieldset>
  14.             ...form fields...
  15.           <div class="form-group">
  16.             <button type="submit" class="btn btn-primary" onclick="$('#formModal').modal({'backdrop': 'static'});" >Submit</button>
  17.           </div>
  18.           </fieldset>
  19.         </form>
  20.       </div>
  21.       <div class="modal-body showThankYou" id="showThankYou" style="display:none">
  22.         <p>Thank you. Your cliuent has been added.</p>
  23.       </div>
  24.       <div class="modal-footer">
  25.       </div>
  26.     </div>
  27.   </div>
  28. </div>