我使用此form validator和ajax();
調用來填充覆蓋圖,然後在確認電子郵件是否存在於我們的數據庫中之後將顯示覆蓋圖。 php文件將決定是否顯示註冊或登錄表單。帶有ajax()調用的表單驗證程序不會執行驗證
我目前的問題是,如果有人點擊提交按鈕(沒有填充任何東西),ajax調用將被做出並驗證跳過。雖然安全措施已到位,但我寧願讓訪問者在登記表格前測試他的電子郵件,以防他已經是用戶。
我已經測試了這幾種不同的方式,但似乎沒有工作。
其它功能:
//turn overlay on/off
function overlayOff() {$("#olContainer").html('');$('#overlay').css({ "display":"none" });}
function overlayOn() {$('#overlay').css({ "display":"block" });}
Ajax調用:
//ajax call
function loadLoginFormOverlay(form) {
event.preventDefault(); // Stop form from submitting normally
$("#olContainer").html(''); //Clear result div
var values = form.serialize(); // Get some values from elements on the page:
$.ajax({ // Send the data using post and put the results in a div
url: "../inc/formLogin.php",
type: "post",
data: values,
success: function(){
$("#olContainer").load('../inc/formLogin.php');
overlayOn();
},
error:function(){
$("#olContainer").html('An error occurred while submitting your email, please refresh your browser and try again.<br>We are sorry for the inconvenience.');
$("#olContainer").append('<input name="Close" type="submit" class="buttsubmit" id="olCloseBtn" value="Close" title="Close" />');
overlayOn();
}
});
}
綁定:
//binding the submit event to the ajax call
$("#preLoginForm").submit(function(event) {
loadLoginFormOverlay($(this));
});
$("#clientForm").submit(function(event) {
loadLoginFormOverlay($(this));
});
驗證:
//executes validation
$.validate({
form : '#preLoginForm, #clientForm',// Header preLoginForm && clientForm validation and AJAX call on success eventHandler
modules: 'security, location', // security for email confirmation, location for country suggestion
onModulesLoaded : function() {
$('input[name="clCountry"]').suggestCountry(); //activate country suggestion
},
onError : function() {
return false; //event.preventDefault();
},
onSuccess : function() {
return false;//event.preventDefault();
}
});
我已經嘗試將提交事件綁定在由驗證生成的onSuccess
事件中,但ajax調用不會發生。 Found someone with the same problem, not solved.
我試過使用一個布爾值,直到onSuccess
事件觸發,將其分配給true,但需要2clicks才能識別修改後的值。
我試着將驗證分配給一個變量,所以它將作爲條件語句的一部分。
我已經跑出了想法,任何人都可以救我嗎? xD 哦,我也搜索了很多,但我認爲爬蟲病了:p