Handle multiple wrappers on an ajax callback

In this case the complete form is rebuild and the original messages array is replaced by the messages array related to the new form state.


/**
 * Form ajax handler.
 */
function _MYMODULE_ajax_handler($form, $form_state) {

  return array(
    '#type' => 'ajax',
    '#commands' => array(       
      ajax_command_replace('#my-form-id' , render($form)),
      ajax_command_remove('.drupal-messages'),
      ajax_command_before('article', '<div class="drupal-messages">' . theme('status_messages') . '</div>'),
    )
  );

}