先关闭,先谢谢你。 我正在用PHP编写注册页面并使用Jquery Validate来检查表单。当表单填写不正确时,它返回错误,但是当它被正确填写时,它只是刷新并且没有完成我在isset $ _POST函数中委派的操作。这是我正在处理的事情:
PHP如果表单不为空
//Escape high risk symbols
$pw= mysqli_real_escape_string($con, $_POST['pass']);
$username= mysqli_real_escape_string($con, $_POST['pass']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$sex = mysqli_real_escape_string($con, $_POST['sex']);
$signedUp = date("Y-m-d H:i:s");
$hash = password_hash($pw, PASSWORD_DEFAULT);
echo 'Email: '.$email;
echo 'Username: '.$username;
echo 'Sex: '.$sex;
echo 'Signed Up: '.$signedUp;
}
?>
这是表格
<form method="post" class="form-signin" id="signup" name="signup">
...
</form>
这是我的验证javascript,似乎它没有发布
<script src="js/formValidate.js"></script>
<script>
// When the document is ready
$(document).ready(function () {
//validation rules
$("#signup").validate({
onkeyup: false,
onfocusout: false,
errorElement: "div",
errorPlacement: function(error, element) {
error.appendTo("div#errors");
},
rules: {
email: {
required : true,
email: true
//equalTo: "#example3-field2"
},
username: {
required: true,
minlength: 5
},
pass: {
required : true,
minlength: 5
},
cPass: {
required : true,
equalTo : "#pass"
},
sex: {
required : true
},
},
messages: {
email: {
required: "You must enter an email address",
email: "Enter a valid email address"
//equalTo: "Field 1 must be equal to Field 2"
},
username: {
required: "You must choose a username",
minlength: "Username must be a minimum of 5 characters"
},
pass: {
required : "You are required to enter a password!",
minlength : "Password must be at least 5 characters!"
},
cPass : {
required : "You are required confirm your password!",
equalTo : "Passwords do not match"
},
sex : {
required : "You are required to choose a sex"
},
},
submitHandler: function(form) {
form.submit();
}
});
});
</script>
答案 0 :(得分:0)
我认为问题是您正在尝试查看FORM是否存在(注册),您需要验证其中一个字段,例如:
if(isset($_POST['email'])){
由于您似乎正在尝试验证表单,并且该索引永远不会出现在$ _POST中。
答案 1 :(得分:-2)
你应该使用类似的东西来检查你的请求是否是POST。
if($_SERVER['REQUEST_METHOD'] === 'POST') {
// do your stuff.
}