javascript - how to use jquery validate .js in wordpress for user name already exist?
Hi I am making a registration form in myWordPress
site
this is the code:
inregister.php
php starting
if(isset($_POST['submit'])){ $reg_result = reg_register();
php ending
<form method="post" action="" name="registerform" id="register-form">
<label >Name</label>
<input name="fname" type="text">
<label >email</label>
<input name="email" id="email" type="text" >
<label >password</label>
<input name="psd" id="psd" type="text" >
<input type="submit" name="submit" />
</form>
infunctions.php
function reg_register(){
$user_name=esc_attr(stripslashes($_POST['uname']));
$user_email=esc_attr(stripslashes($_POST['email']));
$pass=$_POST['psd'];
$userdata = array(
'user_login' => $user_name,
'user_email' => $user_email,
'user_pass' => $pass
);
$user_id = wp_insert_user( $userdata ) ;
}
infooter.php
<script type="text/javascript" language="javascript" src="<?php bloginfo('stylesheet_directory');?>/js/jquery.validate.js"></script>
<script type="text/javascript">
$('#register-form').validate();
</script>
My registration form is working correctly with validation. (i.e. this field is required, please enter a valid emial etc) Now i need to make a validation that this username is already exists. How to do that. Please help
Answer
Solution:
On the server side you can validate wether or not a user exists by using the
http://codex.wordpress.org/Function_Reference/username_exists.
In addition, inserting a user manually into the database is not recommended as WordPress provides an interface for this functionality via
http://codex.wordpress.org/Function_Reference/wp_create_user
To see how to implement it in validate.js (you need output the desired javascript , it via php), see http://jquery.bassistance.de/validate/demo/milk/