Hi,
I'm trying to do the following: I've got a form that is validated with the jQuery Validation Plugin. There is a field which has a couple of rules:
var validator = $("#myForm").validate({
rules: {
emailForRequest: {
required: true,
email: true,
remote: "'emailcheck.php"
}
} ,
...
Now, when one of the rules is broken, more precisely the remote rule, I want to trigger some extra code. So, if the remote rule returns an error and it's error label appears next to the emailForRequest field, I need a callback that does some other things in the background.
In short: can I see which rule triggers the error, see it code-wise I mean, and attach the execution of an extra function to it?
EDIT Ok, thanks to Liam's answer and a better read of the manual I came to this:
rules: {
emailForRequest: {
required: true,
email: true,
remote: {
url: "'emailcheck.php" ,
type: "post" ,
complete: function(data){
if( data.responseText != "true" ) {
alert("Sorry mate, this email address was registered but never activated!");
}
}
}
}
} , ...
But one problem remains. the emailcheck.php script can return 3 different results one of which is true and the other 2 are language dependent. So I would like to sent a json object as the response with a var for the error type (the same in all languages) and a var with the message (translated). So, In my complete function I can then do a check on the error type and respond according to that. Easy enough, except it will screw up the validation standard error that's supposed to appear next to my field and I haven't found a solution for that yet.