views:

114

answers:

2

My jQery 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? Kindly help

+2  A: 

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
        }
    }
  });
});
Nick Craver
I couldn't get that to work, but I didn't think to quote the name! +1
Leo
@ nick i'll try this now
chinni776
yeah it works thanx
chinni776
@chinni776 - Welcome :) Be sure to accept answers via the checkmark so the next user finding this on google finds a working answer quickly :)
Nick Craver
sorry for the delay
chinni776
@chinni776 - Delay is never a problem...we just want the answers here to be as useful as possible to both the asker *and* the next person with this problem...googling for an answer and arriving here :)
Nick Craver
+1  A: 

I had exactly this problem yesterday. The answer is to 'force' the name on the input field, like:

echo $form->input('cheque_number',array('name'=>'InvoiceChequeNumber','value'=>''));

I spent a while trying to avoid doing that, but I couldn't find any alternative. There are no problems for CakePHP when you do it like this.

Leo