如何在cakephp窗体中使用jquery.validate插件 [英] How to use jquery.validate plugin in cakephp form
本文介绍了如何在cakephp窗体中使用jquery.validate插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的jQuery代码是:
My jQuery code is:
$(document).ready(function(){
$('#StudentRegisterForm').validate({
rules: {
email: {
required:true,
email:true
}
}
});
});
并以我的表单电子邮件:
and in my form email:
<td><?php echo $form->input('email',array('class required email')); ?></td>
问题是jquery validate插件工作在输入字段属性'name',但cakephp命名为 data [Student] [email]
。如果我使用这个名称在jquery它抛出一个错误。如果我重命名cakephp中的字段,电子邮件值不会传递到数据库。
The problem is jquery validate plugin works on the input fields attribute 'name' but cakephp names it as data[Student][email]
. If I use this name in jquery its throwing an error. If I rename the field in cakephp the email value is not passed to the database. Is there any other round about way?
推荐答案
你只需要一个小小的调整,使用字符串设置规则,像这样:
You need just need a minor tweak, set the rule using a string, like this:
$(function(){ //short for $(document).ready(function(){
$('#RegisterForm').validate({
rules: {
"data[Student][email]": {
required:true,
email:true
}
}
});
});
这篇关于如何在cakephp窗体中使用jquery.validate插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文