Form with alternative responses

I see tutorials on form handling, with or without Ajax. But the examples show a simple response of “thank you” or similar. Where the action on form submission involves the possibility of a variety of error conditions, how can these be communicated to the user?