Last active
September 9, 2020 08:17
-
-
Save sandman/8278855483720d326e26 to your computer and use it in GitHub Desktop.
Demo of Bootstrap validator double submit bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
$('#payment-form').bootstrapValidator({ | |
// added validators including callback validation for date expiry etc.. | |
}); | |
$("#payment-form").submit(function (event) { | |
// disable the submit button to prevent repeated clicks: | |
$('#submitButton').prop('disabled', true); | |
$('#submitButton').attr("disabled", "disabled"); // Just to be sure | |
// Make some 3rd Party API calls (stripe) | |
//Stripe.createToken.. | |
// Prevent the form from submitting: | |
return false; | |
}); // End of submit handler | |
}); // End of $(document).ready | |
function stripeResponseHandler(status, response) { | |
// Check for an error: | |
if (response.error) { | |
reportError(response.error.message); | |
} else { // No errors, submit the form: | |
var f = $("#payment-form"); | |
// Token contains id, last4, and card type: | |
var token = response['id']; | |
// Insert the token into the form so it gets submitted to the server | |
f.append("<input type='hidden' name='stripeToken' value='" + token + "' />"); | |
// Submit the form: | |
f.get(0).submit(); | |
} | |
} |
the suggestion of adding
on('success.form.bv',function(e){
e.preventDefault(); // <----- THIS IS NEEDED
fixes it for me
guys can I use this to insert data to php my admin??
Nice! ty
guys can I use this to insert data to php my admin??
Indeed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the problem is that you are not using the success.form.bv event like it's recommended in the page: http://bootstrapvalidator.com/examples/ajax-submit/
I think your code should be:
$(document).ready(function () {
});