How to set a validation error via ajax?
If the name of your form is modulename_admin_form() then you can add a function modulename_admin_form_validate(&amp;$form, &amp;$form_state).

In that validate function you can form_set_error() from in that validate function.