Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use jquery.validate plugin in cakephp form

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>

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?

like image 371
chinni776 Avatar asked Jul 20 '10 10:07

chinni776


1 Answers

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
        }
    }
  });
});
like image 196
Nick Craver Avatar answered Oct 15 '22 18:10

Nick Craver