I asked a question [here] recently and it's just not providing me with an answer. Here's what I want to do and you can see my first attempt at the link above:
- User submits form
- Stop default submit action
- check to see if a similar entry exists in database
- If it does, display a notice asking them if they want to submit anyway and give an option to let them submit anyway (enable default action and submit it).
- If it does not, enable the default action on the form and let it submit
I'm at a loss. Any help is appreciated. Thanks gang.
EDIT for Simeon: Here is the code I'm using with your solution:
var forceSubmitForm = false;
$('#purchaser_contact').submit(function(){
if(forceSubmitForm) return true;
if( $("#id").val()=="" ){
if( $("#fname").val()=='' || $("#city").val()=='' ){ alert('First Name and City are required fields. Please fill these in before continuing.'); return false; }
$.ajax({
type: "POST",
url: 'ajax/contactSearch.php',
data: ({ fname: $("#fname").val(), lname: $("#lname").val(), city: $("#city").val(), state: $("#state").val() }),
success: function(d) {
var obj = JSON.parse( d );
if(obj.result != 0){
$("#contactSearch").remove();
$("#button-wrapper").before('<div id="contactSearch">'+obj.result+'</div>');
$("#contactSearch").slideToggle('slow');
} else {
forceSubmitForm = true;
$('#purchaser_contact').submit(); // Form will submit
}
}
});
return false;
} //END IF empty id
});
This won't work until the submit button is pushed a second time (ie, $('#purchaser_contact').submit();
is not submitting the form).
EDIT This never did work for me but Simeon's answer is the closest and he claims it works in all major browsers so if it helps someone, great.