I'm creating a registration form for a client for an event they're hosting. The basic user details are submitted to a third-party system (ie name, email etc.) but the rest of the fields need to be sent via email to the client.
I need something like this to happen :
Here is the code I've tried using, but it gets caught in a loop repeatedly submitting itself to the 'email' page, and never submits to the external url.
If I replace the $('#form1').submit();
with an alert it submits only once to the email page and then displays the alert correctly.
var myvalidator = $('#form1').bValidator(optionsGrey);
$('#form1').submit(function() {
if (myvalidator.isValid()) {
$.ajax({
data: $('#form1').serialize(),
type: "POST",
url: "email_send.asp",
success: function() {
$('#form1').submit();
}
});
}
return false;
});
Any suggestions as to how I can fix this?
preventDefault(); which prevents the form from submitting, and then return; to exit the script. There is no need for a return true; at the end.
Use JQuery to Prevent Multiple Form Submissions To prevent the user from submitting a form multiple times, we'll use JQuery to listen for the submission event. Once the form is submitted, we'll add a disabled attribute to the button to prevent multiple form submissions. Now the user can't click it again.
Try:
$('#form1').unbind('submit').submit();
try unbinding submit event on your success: method of your ajax call by calling unbind
$('#form1').unbind('submit');
$('#form1')[0].submit(); // call native submit
http://api.jquery.com/unbind/
You can use unbind() to revert to the default behaviour.
var myvalidator = $('#form1').bValidator(optionsGrey);
$('#form1').submit(function() {
if(myvalidator.isValid()) {
$.ajax({
data: $('#form1').serialize(),
type: "POST",
url: "email_send.asp",
success: function(){
$('#form1').unbind('submit');
$('#form1').submit();
}
});
}
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With