0

I'm trying to validate if input emailId and phone number exists or not using jQuery Validation plugin(remote method). But i Don't know where i am going wrong. I tried using add method plugin but didn't work.can anyone help me where am i going wrong??

Here is the code.

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
    <script src="http://cdn.jsdelivr.net/jquery.validation/1.14.0/additional-methods.js"></script>

$('#myForm').validate({ // initialize the plugin
            rules: {
                emailId: {
                    required: true,
                    email: true,
                    remote: {
                        url:'verifyEmailOrPhone-'+$('#emailId').val()+'-'+$('#contactNumber').val(),
                        type:'GET',

                }
                },

                contactNumber:{
                    required: true,
                    minlength: 9,
                    maxlength: 10,
                    number: true,
                    remote: {
                        url:'verifyEmailOrPhone-'+$('#emailId').val()+'-'+$('#contactNumber').val(),
                        type:'GET',

                  }
                },

            },   
            messages:{
                emailId:{
                    remote: "emailId already taken"
                    },
                contactNumber:{
                    remote: "phone number exists"
                }   
                },

            submitHandler: function (form) { 
                // for demo
                alert('valid form submitted'); // for demo
                return false; // for demo
            }

        });

html

<div class="margin-top-10  contact-check has-feedback form-group" >
                       <input class="form-control input-lg" name="contactNumber" id="contactNumber" placeholder="Phone Number" size="25" type="text"  value="">
                   </div>
                   <div class="margin-top-10  email-check  form-group has-feedback" >
                       <input class="form-control input-lg" name="emailId" id="emailId" placeholder="Email" size="25"  value=""  type="text">
                   </div>

in console i'm getting http://localhost:8080/SpringMvcExample/verifyEmailOrPhone--?emailId=bhagya%40gmail.com

remote method is returning "emailId=bhagya%40gmail.com" in url where i need to return only input data.

Bhagyashree O
  • 123
  • 1
  • 3
  • 13
  • can you post HTML and PHP, also you can have a look at this http://stackoverflow.com/questions/32543598/jquery-validate-remote-check-if-email-already-exists/32548295#32548295 see if this helps and this one http://stackoverflow.com/questions/32946534/jquery-validation-remote-function-with-additional-data/32952869#32952869 – Shehary Oct 19 '15 at 13:56
  • Hi @Shehary i'm using in jsp. – Bhagyashree O Oct 19 '15 at 14:04
  • *"but didn't work"* is not useful. Please describe in detail exactly what is happening. Is the ajax working? What's the response from the server? – Sparky Oct 19 '15 at 14:26

1 Answers1

2
  1. You're sending a value of true instead of the value of the field

    data: {
        emailId: function() {
            return true; // <- ??
        }
    }
    
  2. You don't need to use the data property at all since the value of the field is already sent by default.

Remove the data property entirely.

Of course this answer assumes your server-side script, which we cannot see, is constructed and working properly.

Sparky
  • 98,165
  • 25
  • 199
  • 285
  • 1)i tried by putting the value of the field but didn't work – Bhagyashree O Oct 19 '15 at 14:16
  • 2) removed the data property but doesn't seems to be working – Bhagyashree O Oct 19 '15 at 14:17
  • @BhagyashreeO, *"doesn't seem to be working"* is not a useful problem description. Are you looking at your console to observe the ajax response? What about the server-side code? You've only shown us half of the picture if you leave out the server-side script. – Sparky Oct 19 '15 at 14:24
  • verifyEmailOrPhone--?contactNumber=8888888888 this is what im getting in console..... – Bhagyashree O Oct 19 '15 at 14:37
  • @BhagyashreeO, that means everything you've shown us is working as you designed it. However, we would have no idea how your server-side script is designed to work or if it's broken. – Sparky Oct 19 '15 at 14:40