I'm using jQuery Validate plugin for field validations on my registration page.
I currently have this code in my validation JS for checking whether the entered username already exists or not:
"remote": {
url: "../assets/php/checkUsername.php",
type: "post",
data: {
username: function() {
return $('#register-form :input[name="username"]').val();
}
}
}
checkUsername.php basically returns true or false based on existence of entered username. This works all fine but I want to optimize it.
Now I have core.php file that already has function called account_exists($username) on it. This function basically returns true or false based on existence of given username as well.
My question is, how can I get rid of checkUsername.php altogether and instead use account_exists function that is in my core.php file?
core.php obviously contains a lot more things so I'm not sure how I can tell my validation script to call the specific function from the core.php.
data: { username: $('#register-form :input[name="username"]').val() }if(isset($_GET['checkUsername'])){ account_exists(); }switch($_POST['function']) { case 'username'....etc.