Php jQuery表单验证等式隐藏字段
我正在编写一个表单,该表单在提交之前经过jQuery验证。其中一个字段是验证码 这个想法非常简单,验证码显示为图像,也存储在隐藏字段中。当用户在输入字段中输入验证码时,它应等于隐藏字段的值。这是我的jQuery代码Php jQuery表单验证等式隐藏字段,php,jquery,captcha,hidden-field,Php,Jquery,Captcha,Hidden Field,我正在编写一个表单,该表单在提交之前经过jQuery验证。其中一个字段是验证码 这个想法非常简单,验证码显示为图像,也存储在隐藏字段中。当用户在输入字段中输入验证码时,它应等于隐藏字段的值。这是我的jQuery代码 <script> $(document).ready(function(){ $("#register").validate({ errorElement: 'div', ignore: 'hidden', rules: { password: {
<script>
$(document).ready(function(){
$("#register").validate({
errorElement: 'div', ignore: 'hidden',
rules: {
password: {
required: true
},
password2: {
required: true, equalTo: "#password"
},
agree: {
required: true
},
captcha: {
required: true, equalTo: "#captcha2"
}
},
messages: {
password2: "Please repeat the same password",
captcha: "The captcha you entered is wrong",
agree: "You have to be at least 16 years old and agree to the terms of service"
}
});
});
</script>
$(文档).ready(函数(){
$(“#寄存器”).validate({
errorElement:'div',忽略:'hidden',
规则:{
密码:{
必填项:true
},
密码2:{
必填项:true,等于:“#密码”
},
同意:{
必填项:true
},
验证码:{
必填项:正确,等号:“#captcha2”
}
},
信息:{
密码2:“请重复相同的密码”,
验证码:“您输入的验证码错误”,
同意:“您必须年满16岁并同意服务条款”
}
});
});
表单的html代码更简单,但我将只显示其中的一部分
<p>
<img src='/includes/captcha.php' />
</p>
<p>
<label for="Captcha">Captcha</label>
<em> *</em><input type="text" name="captcha" id="captcha" size="25"
class="require" minlength="5" />
<input type="hidden" name="captcha2" id="captcha2"
value="<?php echo $_SESSION['captcha'];?>" />
验证码
*
您的会话是否从页面顶部开始?不确定,但我认为会话正在某个地方玩游戏。尝试在验证函数中调试并检查/控制隐藏验证码和文本框值。是的,会话已设置,隐藏字段的值与验证码相同。尝试为隐藏字段指定任何静态值,而不是通过会话&测试它是否工作?是的,提供静态值有效。