Cannot submit a form with jquery validation
Hello,
I am trying to use jquery's ajax framework to check if the data that is entered is valid or not. The form works properly except i cannot get the page to go to action="something.php" file in the form part.
This is what I currently have for my ajax:
- var passback = false;
$(document).ready(function() {
$("#add").submit(function(){
$.post("ajax/validate-company.php",{
company: $("#company_name").val(),
address: $("#address").val(),
address2: $('#address_2').val(),
city: $('#city').val(),
state: $('#state').val(),
zip: $('#zip').val()
}, function(xml) {
if(xml == "bad")
{
alert('This company already exists');
}
else
{
passback = true;
}
},'text');
return passback;
});
});
I am having issues with the "else" portion of my pass back function
my form has the following for the code:
- <form method="post" enctype="multipart/form-data" action="form-parse.php?add_restaurant=yes" id="add" name="add">
So basically what happens is:
- I enter a company into the form and hit submit
- The form will send the data to my validate-company.php file.
- Validate company will return either "good" or "bad"
- If "bad" the form works as expected. it will stop the function by returning false and alert you that it is already in the database
- If "good" the page just sits there, basically returned false. however if you click submit again on the html form the function will go through and do what return: true should do.
If anyone can help with getting the form to submit properly when returned "good" that would be so helpful.
Thanks
Eric