Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Bootstrap Modal to confirm action

I have a form which I wish to submit but once the user clicks the submit button it will show a twitter bootstrap modal which will either let the form continue on to be processed or canceled back to the form page. Is it possible to turn the regular javascript confirm into the 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>
like image 924
Pierce McGeough Avatar asked Oct 16 '13 13:10

Pierce McGeough


People also ask

How can I show data using a modal when clicking a table row using Bootstrap?

On each of your <tr> 's add a data attribute for id (i.e. data-id ) with the corresponding id value and specify a data-target , which is a selector you specify, so that when clicked, bootstrap will select that element as modal dialog and show it.

Is Bootstrap modal responsive?

Bootstrap modals are supposed to be responsive by default. Something to look out for is if you have a width set on your Modal.

How use modal in Bootstrap react?

To get started with using Bootstrap in your React application, you need to install the react-bootstrap package from npm along with the bootstrap v4 package. You will need to install regular Bootstrap for the CSS. After the installation is complete, you can import the modal component and the styling into your module.

How do you call a modal on a button click?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.


1 Answers

You can use the Bootstrap modal as a confirm by enabling a link/button (ie:'btnYes') in the modal that is used to trigger form submission via jQuery...

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

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

like image 134
Zim Avatar answered Oct 17 '22 20:10

Zim