我是PHP的新手,我想在我的PHP项目中应用jQuery验证。以下是jQuery的代码,请您在本节中找到错误。
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
//form validation rules
$("#register-form").validate({
rules: {
username: "required",
joindate: "required",
location: "required",
aboutme: "required",
fileupload: "required",
emailid: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
agreement: "required"
},
messages: {
username: "Please enter your username",
joindate: "please enter join date",
location: "please enter your location",
aboutme: "please write about urself",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
emailid: "Please enter a valid email address",
fileupload: "Please upload a valid image",
agreement: "Please accept our terms and policy"
},
submitHandler: function(form) {
form.submit();
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
答案 0 :(得分:1)
如果它不是强制性的,那么你可以避免jQuery或javascript验证。通过禁用浏览器javascript,有些人可以很容易地解决这个问题。最重要的是,你需要php验证并使其更安全使用html5“required”属性来限制用户向前移动而不输入值
Username: <input type="text" name="username" required />
Password: <input type="password" name="username" required />
Email: <input type="email" name="email" required />
URL: <input type="url" name="url">
您还可以通过在其中添加标题来自定义消息,
Username: <input type="text" name="username" required title="Please enter your username" />
您还可以对您要验证的方式设置条件,请查看此link。
答案 1 :(得分:0)
$(document).ready(function(){
$("#register-form").validate({
rules: {
username: {
required: true
},
joindate: {
required: true
},
location: {
required: true
},
aboutme: {
required: true
},
fileupload: {
required: true
},
emailid: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
agreement: "required"
},
messages: {
username: "Please enter your username",
joindate: "please enter join date",
location: "please enter your location",
aboutme: "please write about urself",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
emailid: "Please enter a valid email address",
fileupload: "Please upload a valid image",
agreement: "Please accept our terms and policy"
},
submitHandler: function() {
document.register-form.submit();
}
});
});
用上面的代码替换你的所有jquery代码并进行测试,它会起作用