Use Bootstrap Modal to Confirm Action

I have a form that I want to submit, but as soon as the user clicks the submit button, he will show a tweeter-bootstrap mod, which will either continue processing the form or cancel it back to the form page. Is it possible to include regular javascript confirmation in bootstrap modal?

<form action="http://localhost.testing/modal-processing.php" class="form-horizontal" role="form" method="GET"> <label>Landlord<span class="mandatory">*</span></label> <select class="form-control input-sm chosen chzn-select" tabindex="1" data-placeholder="Choose a landlord" data-rule-required="true" name="landlord_id" id="landlord_id"> <option value=""></option> <option value="31" >Liam Lawlor</option> <option value="34" >Damian Lavelle</option> <option value="35" >Mick Lally</option> <option value="36" >Joanne Lavelle</option> <option value="37" >Liam Lacey</option> <option value="38" >Laura Luney</option> <option value="39" >Lenihan Enterprises</option> </select> <!-- modal caller --> <a href="#modal-dialog" class="modal-toggle" data-toggle="modal" data-href="http://localhost.testing/modal-processing.php" data-modal-type="confirm" data-modal-title="Delete Property" data-modal-text="Are you sure you want to delete {$property.address_string}?" data-modal-confirm-url="{$base_url}residential-lettings/properties/do-delete/property/{$property.id}"><i class="icon-trash"></i> Modal Submit</a> <!-- proper submit --> <input type="submit"> </form> 
+6
source share
2 answers

The modal use of Bootstrap can be used as confirmation by including a link / button in the modal (that is: "btnYes"), which is used to start submitting the form via jQuery ...

 $('#btnYes').click(function() { // handle form processing here $('form').submit(); }); 

Here is a working demo: http://bootply.com/88094

+10
source

Adding a button to listen for clicks to you is correct:

 $('#myModalButton').click(function(){ //submit form // $('#myForm').submit(); // not working for me // $('#myForm')[0].submit(); //works, but is ugly $('#myForm').trigger('submit'); //works great }); 

As far as I can tell, $ ('form') returns an array. Even $ ('form # myForm') also returns an array.

So,

 $('form')[0].submit(); 

must work.

 $('#myForm').trigger('submit'); 

This is the only way to make it work.

0
source

Source: https://habr.com/ru/post/956090/


All Articles