我正在尝试使用jQuery表单验证插件验证表单。
它在HTML页面中运行良好。但是,当我将相同的代码复制粘贴到PHP页面中的表单时,其行为为PHP_SELF
,表单验证无效。
我的代码:
<form id='registerForm' name='registerForm' method='post' action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<div>
<label for="name">Name</label>
<input type="text" id="name" name="name" />
</div>
<div>
<label for="email">Email</label>
<input type="email" id="email" name="email" />
</div>
<div>
<input type="submit" name="submit" value="Submit"/>
</div>
</form>
<script type="text/javascript" src="jq213.js"></script>
<script type="text/javascript" src="validate.min.js"></script>
<script>
$("#registerForm").validate({
rules:{
name:{
required:true,
minlength:2
},
email:{
required:true,
email:true
},
},
messages:{
name:{
required:"pls enter your name",
minlength:"minimum 2 char for name"
},
email:{
required:"required",
email:"Enter a valid email"
}
}
});
</script>
为什么它不能在PHP自引用表单中工作?如果需要更多信息,请告诉我。
答案 0 :(得分:3)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form id='registerForm' name='registerForm' method='post' action="" >
<div>
<label for="name">Name</label>
<input type="text" id="name" name="name" />
</div>
<div>
<label for="email">Email</label>
<input type="email" id="email" name="email" />
</div>
<div>
<input type="submit" name="submit" value="Submit"/>
</div>
</form>
<script type="text/javascript" src="js/jq213.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
<script>
$("#registerForm").validate({
rules:{
name:{
required:true,
minlength:2
},
email:{
required:true,
email:true
},
},
messages:{
name:{
required:"pls enter your name",
minlength:"minimum 2 char for name"
},
email:{
required:"required",
email:"Enter a valid email"
}
}
});
</script>
</body>
</html>
答案 1 :(得分:2)
试试这个。
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(r.openRawResource(R.raw.key),
"password".toCharArray());
PrivateKey key = (PrivateKey) keystore.getKey("privatekey", "password".toCharArray());
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton(STORAGE_SCOPE))
.setServiceAccountPrivateKey(key)
//.setServiceAccountPrivateKeyFromP12File(new File("/storage/sdcard0/key.p12"))
.build();
答案 2 :(得分:1)
您的代码工作正常,问题是您缺少jQuery文件。添加这两行代码,它应该可以工作。
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
又重要
使用$().ready(function ()
~~
$().ready(function () {
$("#registerForm").validate({
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
}
},
messages: {
name: {
required: "pls enter your name",
minlength: "minimum 2 char for name"
},
email: {
required: "required",
email: "Enter a valid email"
}
}
});
});
答案 3 :(得分:1)
<script type="text/javascript" src="jq213.js"></script>
<script type="text/javascript" src="validate.min.js"></script>
这两行代码不起作用。除此之外一切都还可以。 我已经过测试。如何使这些插件正常运行。
答案 4 :(得分:0)
你可以试试3件事:
"<script></script>"
希望它会有所帮助!