我希望实现jQuery validate插件以在WordPress中验证我的自定义表单,但验证不起作用,尽管有错误,表单仍然提交。
这是我正确完成的事情:
验证脚本是我认为问题所在:
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#wpcf7_298').validate({
rules: {
wordsno: {
required: true,
digits: true
},
dynamictext-419: {
required: true,
email: true
},
select-box: {
required: true,
}
},
messages: {
wordsno: "Please fill the field",
dynamictext-419: "Please enter a valid email address.",
select-box: "Please choose your order type."
}
})
$('#sbbutton').click(function() {
$("#wpcf7_298").valid();});
});
</script>
答案 0 :(得分:3)
您对验证方法的key
是错误的
jQuery(document).ready(function($) {
$('#wpcf7_298').validate({
rules: {
wordsno: {
required: true,
digits: true
},
'dynamictext-419': {
required: true,
email: true
},
'select-box': {
required: true,
}
},
messages: {
wordsno: "Please fill the field",
'dynamictext-419': "Please enter a valid email address.",
'select-box': "Please choose your order type."
}
})
在对象中,具有非字母数字值的键(如-
)必须用单引号/双引号括起来。