As long as the remote
rule receives the proper response from the server, the plugin will automatically toggle the message.
If your PHP result needs validation to fail, do this...
echo 'false';
OR
echo json_encode('some error message');
If your PHP result needs validation to pass, do this...
echo 'true';
"The serverside resource is called via jQuery.ajax (XMLHttpRequest) and gets a key/value pair corresponding to the name of the validated element and its value as a GET parameter. The response is evaluated as JSON and must be
true
for valid elements, and can be anyfalse
,undefined
ornull
for invalid elements, using the default message; or a string, eg. "That name is already taken, try peter123 instead" to display as the error message."
Your second jsFiddle is totally broken, not by the remote
method, but by the code within your errorPlacement
callback.
Removing the errorPlacement
callback, or putting back to its default, at least gets the plugin working again:
Instead of creating br
elements with jQuery to place the label
, just use the errorElement: "div"
option and that will change the label
into a div
and it will naturally appear under the input
because a div
is a block. This way, you can avoid the errorPlacement
option entirely.
errorElement: "div"