簡體   English   中英

php聯系表單提交jquery驗證

[英]php contact form submit with jquery validation

我有一個基本的足夠的聯系表單,使用jquery客戶端驗證。 我開始在ajax中執行表單,但現在認為提交服務器端會更好,因為我需要一個成功頁面來添加Google Analytics跟蹤。 所以ajax表格是這樣的:

    if (i == 0) {
    $.ajax({        
        beforeSend: preloader,
        type    : 'POST',
        url     : './ajax/contact-form.php',
        data    : $('#contact_form').serialize(),
        success : function(data) {
            $('#popup_form').html(data);
        }
    });
}

但現在我想改變它

if (i == 0) // then go to success.php, else do not submit the form. 

i == 0顯然是驗證錯誤計數。 那么,如果我不= 0,如何禁止提交表單?

如果有幫助,這是我的表格

<form action="success.php" id="contact_form" method="post">
<input id="contact_name" name="contact_name" placeholder="name*" type="text" /><span id="contact_name_validate"></span>
<input id="contact_company" name="contact_company" placeholder="company" type="text" />
<input id="contact_email" name="contact_email" placeholder="email*" type="text" /><span id="contact_email_validate"></span>
<input id="contact_telephone" name="contact_telephone" placeholder="telephone*" type="text" /><span id="contact_telephone_validate"></span>
<div id="contact_message"><textarea name="contact_message" placeholder="Enter your message..."></textarea></div>
<input id="contact_button" type="submit" value="Enquire Now" />

您正在尋找的是假的嗎?

if (i == 0) {
    return true; // submits the form if this is a button click / form submit event handler
}

return false; // notice this, stops form from submitting.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM