Reputation: 23
I've ran into a strange problem when playing around with Bootstrap 4 Modals. When I tried to put a form inside a modal - submitting wouldn't do anything and after inspecting the element in Google Chrome I found out that it shows the input fields are outside the form tags.
My code in question is:
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action='test-input.php' method='post' class='ajax-input'>
<input type='text' name='test-input-field'><input type='submit' name='test-submit'>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
But google chrome sees the "modal-body" like this:
<div class="modal-body">
<form action='test-input.php' method='post' class='ajax-input'></form>
<input type='text' name='test-input-field'><input type='submit' name='test-submit'>
</div>
Sadly on IE everything works fine. What can be the problem and is there a way to go around this problem if it persists ?
Upvotes: 2
Views: 626
Reputation: 1065
It looks like you are creating each modal immediately after the <tr>
, still inside the <table>
. This is probably what is causing the issue. You will want to move the modals outside of your table, giving you code something like:
<table>
<? foreach($item in $items) { %>
<tr> ... </tr>
<? } ?>
</table>
<? foreach($item in $items) { %>
<div class="modal" id="modal-<?= $item->id ?>">
...
</div>
<? } ?>
Upvotes: 1