Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sun's avatar
Level 1

How to use Boostrap Modal to submit a form outside of Modal

I am trying to a form, but want to add a confirm feature. However, I don't like the confirm feature from javascript, I am looking for something like bootstrap modal, very pretty.

    <form method="POST" action="{{ route('sms.store') }}">
        @csrf
    <div class="form-group">
        <label for="message">Text Message:</label> <div class="pull-right"><span id="wordCount">0</span> / 160 Characters</div>
        <textarea class="form-control" name="message" id="myText" autofocus></textarea>
    </div>

    <div class="form-group" style="text-align:center;">
        <button type="submit" class="btn btn-primary">
            {{ __('Send Message') }}
        </button>
    </div>
</form>

Modal Button

<div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Save changes</button>
</div>

I read a lot of documents, most of them are submitting the form within the modal. Maybe I am using the wrong thing? Any good examples? Or suggestions? Thank you guys.

0 likes
4 replies
jlrdw's avatar

It's just styling you can style anyway you want.

Cronix's avatar
Cronix
Best Answer
Level 67

Should be pretty simple. Just give your form an id

<form id="the-form" method="POST" action="{{ route('sms.store') }}">

Give the submit button an id

<button id="the-submit" type="submit" class="btn btn-primary">Save changes</button>

Then use jquery (since you're using bootstrap) to submit the form when the submit button is clicked.

$(function() {
    $('#the-submit').on('click', function(e) {
        $('#the-form').submit();
    });
});
Sun's avatar
Level 1

@Cronix Thank you for helping me again. I have never really learned JS systematically. I usually just surf online and try to find a piece of the code and try to learn from it. For example, I learned how to automatically format the phone number using JS or auto fill city and state by insert Zip code using JS. I am also trying to learn Ajax, which is really a challenge. Thank you for helping.

jlrdw's avatar

@Sun and for more ajax examples if you search this forum there are quite a few pages of questions with good answers. Also youtube has some good jquery ajax tutorials.

Please or to participate in this conversation.