function(hostedFieldsErr, hostedFieldsInstance) { if (hostedFieldsErr) { console.error(hostedFieldsErr); return; } submit.removeAttr('disabled'); // Fill in the credit card fields $('#ccnum').val('4111111111111111'); // Example card number $('#cvvnum').val('123'); // Example CVV $('#expmonth').val('01 - January'); // Example expiration month $('#expyear').val('2023'); // Example expiration year $('#postalcode').val('12345'); // Example postal code form.on('submit', function(event) { if (errorOccurred) { event.preventDefault(); // Prevent form submission only if an error occurred return; } event.preventDefault(); // Always prevent default form submission hostedFieldsInstance.tokenize(function(tokenizeErr, payload) { if (tokenizeErr) { console.error(tokenizeErr); alert('There was a problem with your CC info'); errorOccurred = true; // Set flag to true if an error occurred return; } console.log('Got a nonce: ' + payload.nonce); $('#field_1n6vl').val(payload.nonce); // If there are no tokenize errors, submit the form if (!errorOccurred) { form.submit(); // Submit the form only if there are no errors } });
I also checked the Braintree documentation. Did you install the PHP SDK on your server or are you using another SDK. You're missing a lot of details that could help with troubleshooting. Plus, you never set a value for errorOccurred before you set it to true in the nested function. That doesn't follow PHP variable scoping rules. Please be very specific with what you've done so far.
if (errorOccurred) { event.preventDefault(); // Prevent form submission only if an error occurred return; }The form submission is not being stopped. It will show the error alert from my code
alert('There was a problem with your CC info');but, then it continues with the form submission once you click ok on the javascript alert. The
event.preventDefault();Is not stopping the submission.
You have not provided enough details. You need someone to do some hands on debugging on your site and step through the code line by line using XDebug or Kint. I suggest you engage a developer for a couple of hours to help you. Here are some resources:
https://formidable-masterminds.com/project-application/
https://formidable-masterminds.com/developers-directory/
Please login or Register to submit your answer