Keep custom theme when using AJAX submit I am using the following code to switch to a custom theme based on the URL

function job_agent_custom_theme() {
  if (arg(0) == 'vista') {
    return 'vista';
  }
}


This works great and will switch to my "vista" theme when "vista" is in the URL. The problem is that one of my pages has a form that is submitted via AJAX. I created the form using the standard Drupal form API and creating my submit button like so

$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Submit'),
  '#attributes' =&gt; array('class' =&gt; array('submit')),
  '#ajax' =&gt; array(
    'callback' =&gt; '_display_form',
    'wrapper' =&gt; 'ajax_wrapper',      
    'effect' =&gt; 'fade',
    'event' =&gt; 'click',      
  ),
);


So the problem is that when I submit the AJAX form, the page switches to this weird hybrid of the default theme and my custom theme. It's like they are both loaded. Am I missing something? How do I preserve the custom theme when submitting an AJAX form. It also seems really weird to me that the entire page would refresh and switch to a different theme anyway. I would think that defeats the whole purpose of AJAX. I can understand the contents of my ajax_wrapper changing, but not the entire page. Anyway, does anyone know of a way to preserve my theme when submitting via AJAX?

EDIT: Oh and I forgot a big piece to this puzzle. This ONLY happens with anonymous users. If I am logged in, it works as expected and when submitting the form, the custom theme is preserved, but if I am NOT logged in I get the mish mash theme.

THANKS
The form AJAX callback uses /system/ajax as the default. The menu router item for /system/ajax implements a theme callback to try and render the ajax contents in the same theme. For example, perhaps this is a node edit form and you have set node forms to use the same theme as the admin theme. The callback will find that. In your case, it is likely rendering in what it thinks is the default theme. Fortunately, you can specify your own ajax path like so:

$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Submit'),
  '#attributes' =&gt; array('class' =&gt; array('submit')),
  '#ajax' =&gt; array(
    'callback' =&gt; '_display_form',
    'wrapper' =&gt; 'ajax_wrapper',      
    'effect' =&gt; 'fade',
    'event' =&gt; 'click',   
    'path' =&gt; 'vista/system/ajax'   
  ),
);


You'll then have to create a menu item for 'vista/system/ajax', which I guess would be a duplicate of 'system/ajax' without theme callback. Perhaps something like this:

/**
 * implements hook_menu
 */
function mymodule_menu() {
  $items['vista/system/ajax'] = array(
    'title' =&gt; 'AHAH callback',
    'page callback' =&gt; 'ajax_form_callback',
    'delivery callback' =&gt; 'ajax_deliver',
    'access callback' =&gt; TRUE,
    // 'theme callback' =&gt; 'ajax_base_page_theme',
    'type' =&gt; MENU_CALLBACK,
    'file path' =&gt; 'includes',
    'file' =&gt; 'form.inc',
  );
  return $items;
}


Don't forget to clear cache so the new menu item takes affect.

Also, I wanted to bring your attention to the ThemeKey module which is great way to change themes based on path.