I have been working to customize our maintenance page via custom template and hook_preprocess_maintenance_page(), the intent is to provide the maintenance message, some static text, as well as a basic AJAX form that allows the user to select a state, and then a specific location in that state, once they submit they will then be passed to the appropriate location outside of our site.

This is how I am handling the form:

in hook_preprocess_maintenance_page()

$vars['maintenance_header'] = $vars['content'] ? "<p>" . $vars['content'] . "</p>" : "<p>System Maintenance</p>";
$vars['maintenance_content'] = "<p><span class='feature'>Don't go anywhere!</span></p>";
$maintenance_form = drupal_get_form('ajax_example_simplest');
$vars['maintenance_join_form'] = drupal_render($maintenance_form);

in maintenance-page.tpl.php

<?php print $maintenance_header; ?>
<?php print $maintenance_content; ?>
<?php print $maintenance_join_form; ?>

In building the form I noticed that when the Ajax callback fires, the contents of $vars[maintenance_header] is printed to an alert window on the screen, instead of the page being updated as I expect. To validate if this was an issue with my form specifically, I grabbed the simple ajax example which is linked below, and the behavior is exactly the same. https://api.drupal.org/api/examples/ajax_example%21ajax_example.module/function/ajax_example_simplest/7

In searching for questions around this I continue to find general ajax questions, and questions about theming the maintenance page, but nothing that covers using an ajax form within the maintenance page, so I have started this new topic to see if others have encountered this specific issue. I am wondering whether an ajax form simply won't work on a custom maintenance page or if this is related to how I am handling the form in the preprocess hook?

Thank You, Rose

  • Hi and welcome to Drupal Answers. Complex operations on a maintenance page does not sound very good to me.
    – Wtower
    Commented Apr 30, 2015 at 13:40
  • Hi @Wtower, Thanks for your response! I understand that concern. As a last resort we can use a basic form with javascript, but the preference is to use Ajax if possible. I am hoping that it is possible to use Ajax, but if it isn't I want to understand why. Commented Apr 30, 2015 at 14:00
  • I'm disagreeing with the close votes to this question. This is an interesting question but not too broad either.
    – AKS
    Commented May 4, 2015 at 20:35

1 Answer 1


When you put your site to offline mode, the menu router system (which is called first when a request is received to serve a page).

By default, Ajax forms are handled from the path system/ajax, which is not allowed when the site is in offline mode. This is not an issue with Drupal itself, it's just that when a site is in offline mode, there is no guarantee that any system is in working condition.

Ajax forms require the form to be cached, and that cache storage is the database unless you alter otherwise. When the database connection is failed, Drupal returns the same maintenance-mode page. Now, if you embed an Ajax form, imagine how there will be a recursion.

If you still need an Ajax form, you need to implement hook_menu_site_status_alter() to alter the site status for a specific path. Then, in your form, your will need to turn off caching ($form_state['no_cache'] = FALSE), and add your own #ajax properties with especially ['#ajax']['path'] set to your custom path that bypasses site status check (from the hook_menu_site_status_alter() hook).

I didn't bother to write an example since your question indicates you already have the Ajax form setup. Disable its cache, add a custom path to handle the submitted data, and make that path accessible with a hook_menu_site_status_alter() hook.

  • Thank you very much! This is just the type of answer I was hoping for. I appreciate the explanation. Also for pointing me in the right direction with hook_menu_site_status_alter(). Commented May 7, 2015 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.