form_get_errors() is NULL when calling it in an AJAX form callback I have a form with a bunch of required fields that all have the same callback. Here's a single field example:

$form['name'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Name'),
    '#required' =&gt; TRUE,
    '#ajax' =&gt; array(
      'callback' =&gt; 'callback_show_buttons',
      'wrapper' =&gt; 'formwrapper',
    ),
  );


formwrapper is a wrapper around the entire form:

$form['#prefix'] = '&lt;div id="formwrapper"&gt;';
$form['#suffix'] = '&lt;/div&gt;';


Here's the callback, inspired by this guy's code:

function callback_show_buttons($form, &amp;$form_state) {
    $allajaxchanges = array( '#type' =&gt; 'ajax', '#commands' =&gt; array() );

    if ( form_get_errors() ) {
        $form_state['rebuild'] = TRUE;
        $allajaxchanges['#commands'][] = ajax_command_replace( "#formwrapper", render($form) );
    }

 return $allajaxchanges;


If I inspect form_get_errors(), it is always NULL, no matter if I validate the form in code or not. drupal_get_messages() is also completely empty, and theme('status_messages') also has nothing in it (these solutions were suggested here). These methods do return something if I submit the form in a non-AJAX way.

Anyone have any idea how to check if a form has errors in it if these don't work?
I found a way to make this work.

I haven't fully investigated this for issues yet but it works with and without javascript enabled.

My use case was only running  my validation if other validation passed:

/**
 * Custom validation function for some form.
 */
function MODULE_NAME_custom_form_validate(&amp;$form, &amp;$form_state) {
  if (isset($form_state['storage']['errors']) &amp;&amp; !empty($form_state['storage']['errors'])) {
    return;
  }
  // Do our extra validation here since other validation passed.
}