I have a multistep form where the page shows one form at a time. If the form validates it hides the first and shows the next form. But i get an error if the user hits submit multiple times. How can I disable the submit button when a valid #step1 is submitted and reactivate it when the next form loads.
<script type="text/javascript">
$(document).ready(function() {
$('#step1').bootstrapValidator({
message: 'This value is not valid',
live: 'disabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitHandler: function(validator, form, submitButton) {
$.ajax({
type: "POST",
url: "scripts/process-step2.php",
data: $('#step1').serialize(),
success: function(msg){
},
error: function(){
alert("error");
}
});//close ajax
},
excluded: ':disabled',
fields: {
coverage: {
validators: {
notEmpty: {
message: 'Please select level of coverage'
}
}
},
insuredBy: {
message: 'Please Make a Selection',
validators: {
notEmpty: {
message: 'Please Make a Selection'
}
}
}, // end dropdown
startDate: {
message: 'Please Make a Selection',
validators: {
notEmpty: {
message: 'Please Make a Selection'
}
}
} // end dropdown
} // end field
});// bootstrapValidator
$('#step2').bootstrapValidator({
message: 'This value is not valid',
live: 'disabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitHandler: function(validator, form, submitButton) {
$.ajax({
type: "POST",
url: "scripts/process-step3.php",
data: $('#step2').serialize(),
success: function(msg){
$.ajax({
type: 'POST',
url: "scripts/send-vars.php",
cache: false,
datatype: "html",
success: function(data){
//alert(data);
document.location.href = 'confirmation.php';
}
});
},
error: function(){
alert("error");
}
});//close ajax
},
fields: {
fname: {
validators: {
notEmpty: {
message: 'The first name is required'
}
}
},
lname: {
validators: {
notEmpty: {
message: 'The last name is required'
}
}
},
email: {
validators: {
// notEmpty: {
// message: 'The value is not a valid email address'
// },
regexp: {
regexp: /^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$/i,
message: 'Please enter a valid email'
}
}
},
phone: {
validators: {
notEmpty: {
message: 'Please enter your phone number'
},
regexp: {
regexp: /^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/i,
message: 'Please enter a valid phone number. Ex: (111) 222-3333 | 1112223333 | 111-222-3333)'
}
}
}
} // end field
});// bootstrapValidator
}); //ready(function
</script>