I'm trying to check on email field blur, if the email already exists in db. My code is now:
<script type="text/javascript">
$(document).ready(function () {
// Validation
$("#soutez").validate({
rules: {
email: {
required: true,
email: true,
remote: "check-email.php",
},
},
messages:{
email:'Email address exists.'
},
onkeyup: false,
onblur: true,
});
});
</script>
And the php code is
$email= $_GET['email'];
echo $email;
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
global $wpdb;
$email_exists = $wpdb->get_row('SELECT COUNT(*) as count from reg_form_new WHERE email = "'.$email.'"');
if ( $email_exists->count == 0 ) { echo 'true'; } else { echo 'false'; }
exit; }
The php code returns true/false correctly, but for some reason it doesn't work with the jQuery script. Anyone can tell me what I'm doing wrong? Thanks