Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery callback validation

Is there a way to perform a callback function with jquery's validation plugin that can look for the function in a different controller?

Meaning I have my register controller however I want it to look inside my users model that houses EVERYTHING user related and perform the is_username_available function.

like image 526
Jeff Davidson Avatar asked Apr 19 '26 05:04

Jeff Davidson


1 Answers

If your validation function is just called is_username_available, you will need to create a decorator for this method, and allow it to be called publicly from your controller.

function validation_username_available($username)
{
    if ($this->is_username_available($username))
        die("true");
    die("false");
}

Then you make an AJAX call to /register/validation_username_available/Bob and read the output, either true or false.

Also, your validation function is_username_available should really be prefixed with an underscore, like _is_username_available. Otherwise it can be accessed publicly through /register/is_username_available/Bob. That is probably something you don't want.

like image 55
kba Avatar answered Apr 20 '26 19:04

kba