简体   繁体   English

php联系表单提交jquery验证

[英]php contact form submit with jquery validation

I have a basic enough contact form that uses jquery client side validation. 我有一个基本的足够的联系表单,使用jquery客户端验证。 I started by doing the form in ajax, but now think it will be better to submit it server side, as I need a success page to add Google Analytics tracking on. 我开始在ajax中执行表单,但现在认为提交服务器端会更好,因为我需要一个成功页面来添加Google Analytics跟踪。 So the ajax form went like this: 所以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);
        }
    });
}

But now I want to change it to 但现在我想改变它

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

The i==0 is obviously the validation error count. i == 0显然是验证错误计数。 So how can I disable the form from submitting if i doesn't = 0? 那么,如果我不= 0,如何禁止提交表单?

If it helps, here is my form 如果有帮助,这是我的表格

<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" />

Is what you are looking for return false? 您正在寻找的是假的吗?

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