I have a modal that makes the registration of products. I wanted to submit a form inside the modal without leaving the modal.
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<form method="post">
<button type="submit">Submit</button>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
One of the most common use cases you see around the web is that of the Login Modal, logging in via a form inside a modal.
Modal verbs show possibility, intent, ability, or necessity. Because they're a type of auxiliary verb (helper verb), they're used together with the main verb of the sentence. Common examples include can, should, and must.
In my case I only put make the submit button one the footer body and remove the data-dismiss i.e:
<div class="modal-content">
<form id="role-form" method="get">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">تعديل صلاحيات المدير - {{$user->username}}</h4>
</div>
<div class="modal-body">
<div class="form-group col-md-12">
<select id="role" name="role" class="form-control">
<option selected disabled>الصلاحية</option>
<option value='1'>مدير</option>
<option value='2'>مشرف</option>
</select>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" >حفظ</button>
<button type="button" class="btn btn-default" data-dismiss="modal">إلغاء</button>
</div>
</form>
</div>
Firstly, set an id on your <form>
tag:
<form id="myForm" method="post">
...
</form>
If you were using jQuery (highly recommended), you could do this:
$(function(){
$('#myForm').on('submit', function(e){
e.preventDefault();
$.post('http://www.somewhere.com/path/to/post',
$('#myForm').serialize(),
function(data, status, xhr){
// do something here with response;
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With