Bootstrap Modal before form Submit

前端 未结 5 1494
野性不改
野性不改 2020-12-23 09:52

I\'m new to Modals, I have a Form and when the user clicks submit, It will show a Modal confirming if the user wants to submit, the modal also contains the user input from t

5条回答
  •  执笔经年
    2020-12-23 10:12

    So if I get it right, on click of a button, you want to open up a modal that lists the values entered by the users followed by submitting it.

    For this, you first change your input type="submit" to input type="button" and add data-toggle="modal" data-target="#confirm-submit" so that the modal gets triggered when you click on it:

    
    

    Next, the modal dialog:

    
    

    Lastly, a little bit of jQuery:

    $('#submitBtn').click(function() {
         /* when the button in the form, display the entered values in the modal */
         $('#lname').text($('#lastname').val());
         $('#fname').text($('#firstname').val());
    });
    
    $('#submit').click(function(){
         /* when the submit button in the modal is clicked, submit the form */
        alert('submitting');
        $('#formfield').submit();
    });
    

    You haven't specified what the function validateForm() does, but based on this you should restrict your form from being submitted. Or you can run that function on the form's button #submitBtn click and then load the modal after the validations have been checked.

    DEMO

提交回复
热议问题