How to use jquery.validate plugin in cakephp form

前端 未结 3 914
天涯浪人
天涯浪人 2021-01-02 09:39

My jQuery code is:

$(document).ready(function(){   
  $(\'#StudentRegisterForm\').validate({          
    rules: {
      email: {
        required:true,
            


        
相关标签:
3条回答
  • 2021-01-02 10:33

    The first one is better to use, because this will maintain cake this->data structure, but second one is not. This is to remind that, when you will use the data[modelname][fieldname] give the class name in the input aray like:

    <?php echo $form->input('email',array('type'=>'text','class' => array('required','email'),'error'=>false,'label'=>false,'div'=>false));  ?>
    
    0 讨论(0)
  • 2021-01-02 10:41

    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
            }
        }
      });
    });
    
    0 讨论(0)
  • 2021-01-02 10:43

    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.

    0 讨论(0)
提交回复
热议问题