My purpose is to not allow the same user to register again, therefore I'm validating the username against existing usernames in the database. It is working properly but it takes a long while to perform the validation.
(function ($) {
FormValidation.Validator.existingUserCheck = {
validate: function (validator, $field, options) {
var value = $field.val();
var cnt = 0;
if (value)
{
$.ajax({
type: 'post',
url: '<?php echo base_url('check - user - exist'); ?>',
data: {
user_name: value
},
dataType: 'json',
async: false,
success: function (response)
{
if (response === 'true')
{
cnt = 1;
}
}
});
}
if (cnt === 1)
{
return {
valid: false,
message: 'Username is taken'
};
} else {
return {
valid: true
};
}
}
};
}(window.jQuery));