jack
jack

Reputation: 473

cakephp jquery validator

I am trying to use jquery validator in a cakephp project.There is probem with jquery I think,something wrong with selector id of my form..I can not even alert any message inside. I am completely a fresher.

I used following code

$(document).ready(function(){        $('#UserQuickCompanyRegisterForm').validate({
       rules: {
            "data['User']['email']": {
               required: true,
               email: true
           }
        }
       });        });

and my form is like this.

echo $form->create('User', array('action' => 'quick_company_register','inputDefaults'=> array('label'=>false)));

and it outputs somthing like below.

<form id="UserQuickCompanyRegisterForm" accept-charset="utf-8" method="post" action="/cityportal/index.php/users/quick_company_register" novalidate="novalidate">.

what i am doing wrong...thanks in advance

Upvotes: 0

Views: 2585

Answers (1)

jack
jack

Reputation: 473

its solved.I was making mistake with element id.Instead of id i used name attrbute."Silly me".After a ;ong fat burning hour i got thit following code wrking

<script type="text/javascript">     $(function(){           $.validator.addMethod("alphanum", function(value, element) {
            return this.optional(element) || /^[a-z0-9/_]+$/i.test(value);
        }, "Username must contain only alphanumeric.");

       jQuery.validator.addMethod("exactlength", function(value, element, param) {       return this.optional(element) || value.length == param;        }, jQuery.format("Please enter exactly {0} characters.")); 
             $('#UserQuickCompanyRegisterForm').validate({          debug: false,
       errorClass: "authError",
       errorElement: "span",
        rules: {    
            "data[User][username]": {
               required: true,
               alphanum: true,
               minlength: 4,
               maxlength: 30
           },
           "data[User][password]": {
               required: true,
               minlength: 6
           },
           "data[User][password1]": {
               required: true,
               equalTo: "data[User][password]"
           },
           "data[User][first_name]": {
               required: true,
               maxlength: 30,
               alphanum: true
           },
           "data[User][second_name]": {
               required: true,
               maxlength: 30,
               alphanum: true
           },
           "data[ZIP][zipcode]": {
               required: true,
               number:true, 
                exactlength: 5
           },

            "data[User][email]": {
               required: true,
               email: true
           },
           "data[User][telephone]": {
               number: true,
               exactlength: 10
           }
       },
       highlight: function(element, errorClass) {
        $(element).removeClass(errorClass);
        }
       });        });
       </script>

Upvotes: 1

Related Questions