我刚刚验证了我的表单,我找到了一个使用 jquery 的教程。唯一缺少的是将数据发送到适当的地址。我怎么做?
这是我的表单 HTML 代码示例
<form id="register-form">
<div class="four columns alpha contact-form">
<label>prefix</label>
<input type="text" />
<label><span class="asterisk">*</span>first name</label>
<input type="text" name="firstname"/>
<label><span class="asterisk">*</span>middle name</label>
<input type="text" name="middlename"/>
<label><span class="asterisk">*</span>last name</label>
<input type="text" name="lastname"/>
<label><span class="asterisk">*</span>email address</label>
<input type="text" name="email"/>
</div>
</form>
这是用于验证我的表单中的数据的 Jquery。
/* 基本 jQuery 验证表单演示代码 版权所有 Sam Deering 2012 许可证:http ://www.jquery4u.com/license/ */
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
//form validation rules
$("#register-form").validate({
rules: {
firstname: "required",
middlename: "required",
lastname: "required",
email: {
required: true,
email: true
},
zip: "required",
city: "required",
subject: "required",
message: "required",
agree: "required"
},
messages: {
firstname: "Please enter your first name",
middlename: "Please enter your middle name",
lastname: "Please enter your last name",
email: "Please enter a valid email address",
zip: "Please enter your zip code",
city: "Please state your city",
subject: "Please state your inquiry",
message:"Please include a short message"
},
submitHandler: function(form) {
form.submit();
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
我还不擅长 jquery,目前我还在学习。我读过我需要使用这个 .serialize() 来获取数据。不确定我是否正确