javascript - Implementing a live email checker with a syntax email checker -


i followed example, http://formvalidation.io/examples/using-data-returned-validator/, , able implement simple validation email , usernames. found demo/example uses ajax call live email checker php script.

what have not figured out how implement (combine) live username checker standard validator both checks see if email of valid format in addition available use, not registered member already. messing javascript, have gotten validator see php script, check_email.php using ajax post.

however don't have right syntax make validator make use of result of php script return message 'duplicate" or "email in use". html email:

<!-- email --> <div class="form-group">   <div class="row">     <label class="col-xs-6 control-label">email address</label>     <div class="col-xs-6"  style='clear:left;width: 50%;'>       <input type="text" class="form-control email" name="email" />     </div>   </div> </div> 

the relevant part of javascript:

<script>   $(document).ready(function() {     $('#taskform').formvalidation({       framework: 'bootstrap',       icon: {         // required: 'fa fa-asterisk',         valid: 'glyphicon glyphicon-ok',         invalid: 'glyphicon glyphicon-remove',         validating: 'glyphicon glyphicon-refresh'       },       fields: {          'email': {            validators: {             notempty: {               message: 'the email address required'             },             emailaddress: {               message: 'the input not valid email address'             }             ,             remote: {               type: 'post',               url: 'check_email.php',               message: 'duplicate or whatever ...',               cache: false,               success: function(result){                 var result=remove_whitespaces(result);                 if(result=='')                {                   // ...                 }               }             }           }         },       }     })   }); </script> 

to see demo form visit http://dottedi.us/validation/validator.php. illustrate live checker works use username of 'sowhat' , email address of 'sowhat@dottedi.biz' test. have username working separately username checker show works, not desired method. email broken code.

i can modify check_email.php if necessary. returns $html='email exists'; if duplicate.

the question: how change structure, syntax of remote function can make use of response check_email.php?

oh, , here php code in check_email.php:

<?php include ("mysql_connection.php");  $html = ""; if(isset($_post['email']) && !empty($_post['email'])) {   $email=strtolower(mysql_real_escape_string($_post['email']));   $query="select * members lower(email)='$email'";   $res=mysql_query($query);   $count=mysql_num_rows($res);    if($count > 0){ $html='email exists'; }else{ $html=''; } }  echo $html;  ?> 

i kept digging , found answer at: http://formvalidation.io/validators/remote/

1) changed relevant javascript to:

remote: {     message: 'this email address taken',     url: 'check_email.php',     type: 'post' } 

2) changed check_email.php return json format response:

if ( $count > 0 ) { $status = false; } else { $status = true; }  if(isset($status)) {   $data = array(     "valid"     => $status,     "email"     => $email // optional   );  echo json_encode($data); } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -