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' => 'textfield', '#title' => t('Name'), '#required' => TRUE, '#ajax' => array( 'callback' => 'callback_show_buttons', 'wrapper' => 'formwrapper', ), );
formwrapper
is a wrapper around the entire form:
$form['#prefix'] = '<div id="formwrapper">'; $form['#suffix'] = '</div>';
Here’s the callback, inspired by this guy’s code:
function callback_show_buttons($form, &$form_state) { $allajaxchanges = array( '#type' => 'ajax', '#commands' => 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?