Skip to content
Snippets Groups Projects
Commit 3768ccfe authored by mattwire's avatar mattwire
Browse files

Prevent multiple submission

parent ebf13d61
Branches
Tags
No related merge requests found
......@@ -5,7 +5,6 @@
(function($, CRM) {
var buttonText;
var stripeFormSubmitted = false;
// Response from Stripe.createToken.
function stripeResponseHandler(status, response) {
......@@ -26,13 +25,12 @@
+ '</ul>'
+ '</div>');
stripeFormSubmitted = false;
$form.data('submitted', false);
$submit.prop('disabled', false).attr('value', buttonText);
}
else {
var token = response['id'];
// Update form with the token & submit.
// copyCCDetails($form);
removeCCDetails($form);
// We use the credit_card_number field to pass token as this is reliable.
// Inserting an input field is unreliable on ajax forms and often gets missed from POST request for some reason.
......@@ -69,7 +67,7 @@
// Get the form containing payment details
$form = getBillingForm();
if (!$form) {
if (!$form.length) {
debugging('No billing form!');
return;
}
......@@ -106,19 +104,26 @@
$form.unbind('submit');
// Intercept form submission.
$(document).on('submit', $form, function(event) {
event.preventDefault();
$form.on('submit', function(event) {
submit(event);
});
function submit(event) {
if (stripeFormSubmitted === true) {
debugging('already submitted');
event.preventDefault();
$form = getBillingForm();
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
alert('Form already submitted. Please wait.');
return true;
} else {
// Mark it so that the next submit can be ignored
// ADDED requirement that form be valid
if($form.valid()) {
$form.data('submitted', true);
}
}
stripeFormSubmitted = true;
$form = getBillingForm();
$submit = getBillingSubmit();
var isWebform = getIsWebform();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment