javascript - How to check if username exists without refreshing page using wordpress -
i want check text field in form if username exists in database or not.i want without refreshing page , using wordpress.i know possible through ajax have tried ajax in wordpress , ajax code didn't run on it. kindly provide piece of code or helpful link. last time have tried didn't work:
<?php if(!empty($user_name)){ $usernamecheck = $wpdb->get_results("select id wp_teacher_info user_name='$user_name'"); if(!empty($usernamecheck)){ echo'username not available'; } else { } }?> <label for="user_name" id="user_name">username: </label> <input type="text" name="user_name" id="user_name" required/> <span id="user-result" ></span> <script type="text/javascript"> jquery("#user_name").keyup(function (e) { //user types username on inputfiled var user_name = jquery(this).val(); //get string typed user jquery.post('teacher_form.php', {'user_name':user_name}, function(data) { jquery("#user-result").html(data); //dump data received php page }); }); </script>
use
if(!empty($_post['user_name']){ $user_name = $_post['user_name'];
to be
<?php if(!empty($_post['user_name']){ $user_name = $_post['user_name']; $usernamecheck = $wpdb->get_results("select id wp_teacher_info user_name='$user_name'"); if(!empty($usernamecheck)){ echo'username not available'; } else { } } ?>
but keyup event call ajax each keyup .. can use **.blur()**
instead of **.keyup()**
Comments
Post a Comment