jquery validation remote error messages
hey guys, i'm trying to find out if when making a remote connection in my validation, is it possible to return cusom error messages?
here is the code i'm using at the moment.
- $("#reg-form").validate({
rules: {
email_address: {
required: true,
remote: {
url: "localhost/validate/email_address",
type: "post",
data: {
email_address: function() {
return $("#email_address").val();
}
}
}
}
- }
- });
now when connected to localhost/validate/email_address i want it to return different error messages depending on the constraint.
ie. my php method
- public function validate_email_address()
{
$request = $this->get_request();
$email_address = $request->post()->email_address;
if ($request->is_ajax() && !empty($email_address))
{
$email = new Email_Address(array(
'value' => $email_address
));
$user = $this->get_model('user:users');
if (!$email->is_valid())
{
echo 'Invalid email address';
}
else if ($user->email_address_registered($email_address))
{
echo 'Email address already registered';
}
else
{
echo 'true';
}
}
else
{
// 404 error
}
}
is this possible please?...if so how?
thank you