Ajax form submit - how to recognize if form contains errors in ajax callback? I have a simple form with ajax submit:

function activit_registration_form($form, $state) {

  $form["ajax-start"] = array("#markup" =&gt; "&lt;div id='registration-form-ajax'&gt;");

  // ... some form elements are here            

  $form["submit"] = array(
      "#type" =&gt; "submit",
      "#value" =&gt; t("Odoslať"),
      "#ajax" =&gt; array(
          "callback" =&gt; "activit_registration_form_ajax",
          "wrapper" =&gt; "registration-form-ajax",
          "effect" =&gt; "fade"));

  $form["ajax-end"] = array("#markup" =&gt; "&lt;/div&gt;");

  return $form;

}


Ajax callback:

function activit_registration_form_ajax($form, $state) {

  return $form;
}


Validation:

function activit_registration_form_validate($form, $state) {

  if(!valid_email_address($state['input']['email'])) { form_set_error('email', 'email'); }
  if(strlen(strval($state['input']['name']))&lt;3) { form_set_error('name', 'meno'); }
  if(strlen(strval($state['input']['tel']))&lt;6) { form_set_error('tel', 'tel'); }

}


Ajax callback is now returning the same form, but I would like to achieve returning just a simple string instead of the form when form does not contain any errors. 

What is the best way to recognize if a form contains errors or not in ajax callback?
You can define the form status in $form_state and check the status during rebuilding form.

Example code:

function activit_registration_form($form, $state) {

  if (isset($state['submit_success'])) {
    $form['ajax_form']['message'] = array("#markup" =&gt; t('Thanks for your submission.'));
  }
  else {

    $form["ajax_form"] = array(
      "#prefix" =&gt; "&lt;div id='registration-form-ajax'&gt;",
      "#suffix" =&gt; "&lt;/div&gt;",
    );

    // define form elements under 'ajax_form', such as
    // $form["ajax_form"]["element_1"] = array( ... );

    $form['ajax_form']["submit"] = array(
      "#type" =&gt; "submit",
      "#value" =&gt; t("Odoslať"),
      "#ajax" =&gt; array(
        "callback" =&gt; "activit_registration_form_ajax",
        "wrapper" =&gt; "registration-form-ajax",
        "effect" =&gt; "fade",
      ),
    );
  }

  return $form;
}

function activit_registration_form_ajax($form, $state) {
     return $form['ajax_form'];
}

function activit_registration_form_validate($form, &amp;$state) {
  $has_error = FALSE;

  if (!valid_email_address($state['input']['email'])) {
    form_set_error('email', 'email');
    $has_error = TRUE;
  }
  if (strlen(strval($state['input']['name']))&lt;3) {
    form_set_error('name', 'meno');
    $has_error = TRUE;
  }
  if (strlen(strval($state['input']['tel']))&lt;6) {
    form_set_error('tel', 'tel');
    $has_error = TRUE;
  }

  $state['submit_success'] = !$has_error;

  $state['rebuild'] = TRUE;
}