我有一个表格,用于在允许输入新作者之前检查作者是否在我的数据库(书店网站)中。
这部分工作完美,作者被发现并提醒用户,但是当一个条目可以提交时,它不会提交......
它只是什么都不做。下面的代码是检查器,然后下面是不工作的提交功能......基本上如果验证作者很好,那么它应该提交但目前不是。我在网站上的另一个表单上使用了类似的方法,它可以工作,但是这个页面上有多个表单,所以这可能是个问题?
var author = $("#author");
var authortext = $("#authortext");
var authorForm = $("#addauthor");
//Author Validation
function validateAuthor()
{
author.css('border', '');
if (author.val().length == 0)
{
author.css('border', '2px solid red');
authortext.text("Please enter an author.");
return false;
}
else
{
$.ajax({
type: "POST",
url: "authorcheck.php",
data: 'author='+ author.val(),
//Stops the query being cached.
cache: false,
//The function when query accepted.
success: function(result)
{
if (result == 1)
{
author.css('border', '2px solid red');
authortext.text("Author has been added already.");
return false;
}
else
{
authortext.text("Correct entry.");
return true;
}
}
});
}
//Forms are submitted if no errors or blank values are found. The server side checks are still done later if the user has javascript disabled.
authorForm.submit(function()
{
if (validateAuthor())
{
return true;
}
else
{
return false;
}
});