Jquery Remote Validation Rule - php email check failing -


i have been scanning interwebs many days now, , have tried posted resolve issue. trying (like many other posts), send remote mysql query via remote validation.. there has been debate on proper format of return data (like json_encode or not) , have tried both suggestions no avail.

jquery code

    $('#register-form-step-1').validate({  // initialize plugin     rules:     {         confirmemail:         {             equalto: "#clientemailaddress"         },         clientpassword:         {             rangelength: [6,32],             required: true         },         clientusername:         {             minlength: 4,             required: true,             remote:             {                 async:false,                 type:'post',                 url:'<?php echo base_url("home/checkusername")?>',                 data: {                 clientusername: function() {                 return $("#clientusername").val();                 }},                 success: function(data)                 {                     console.log(data);                     if (string(data) === string('true'))                     {                         //not registered                         console.log("not registered");                         return true;                     }                     else                     {                     console.log(data);                         //already registered                         console.log("already registered");                     }                 },                 error: function()                 {                     console.log("there error");                 }             }         },         clientemailaddress:         {             async:false,             required: true,             email: true,             remote:             {                 type:'post',                 url:'<?php echo base_url("home/checkemail")?>',                 data: {                 clientemailaddress: function() {                 return $("#clientemailaddress").val();                 }},                 success: function(data)                 {                     console.log(data);                     if (string(data) === string('true'))                     {                         //not registered                         console.log("not registered");                         return true;                     }                     else                     {                         //already registered                         console.log("already registered");                     }                 },                 error: function()                 {                     console.log("there error");                 }             }                }     },     submithandler: function ()     {         $.ajax({             type: 'post',             url: '<?php echo base_url("home/register")?>',             data: $('#register-form-step-1').serialize(),             success: function ()             {                 alert('success')                 console.log('form submitted');                 $("#register-form-1").modal('hide');                 $("#register-form-2").modal('show');             },             error: function(data, textstatus, jqxhr) {                   alert('error')             }         });          return false; // ajax used, block normal submit     } }); 

php code

    public function checkemail() {      $email = mysql_real_escape_string($_post['clientemailaddress']);      $qresult = $this->db->query('     select clientemailaddress clientdata clientemailaddress = "'.$email.'" limit 1     ');      $result = true;      if ($qresult->num_rows == 1)     {         $result = false;     }      header('content-type: application/json');     echo json_encode($result);  } 

replace line in php

echo json_encode($result); 

by

echo json_encode(array($result)); 

and add datatype json in js

otherwise can try

echo 1 or 0; return; 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -