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.
- <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:
- <div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="formModalLabel">Client Add Form</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body showform" id="formBody">
- <iframe name="formSubmitFrame" id="formSubmitFrame" style="display:none;" width="0" height="0"></iframe>
- <form action="xxxxxxxxxxxxxxxx" method="post" target="formSubmitFrame" class="needs-validation" role="form" id="form">
- <fieldset>
- ...form fields...
- <div class="form-group">
- <button type="submit" class="btn btn-primary" onclick="$('#formModal').modal({'backdrop': 'static'});" >Submit</button>
- </div>
- </fieldset>
- </form>
- </div>
- <div class="modal-body showThankYou" id="showThankYou" style="display:none">
- <p>Thank you. Your cliuent has been added.</p>
- </div>
- <div class="modal-footer">
- </div>
- </div>
- </div>
- </div>