I'm currently showing a drupal form via the admin overlay. I'm using jQuery to perform the processing of the form.

The problem I have is how do I close the overlay on submit? right now the only way to close the overlay is by pressing the X at the top right (well based on the default theme), which is just a .

Now I'm presuming that I could somehow change the form to add the "overlay-close" to the submit button, but I'm not sure how to do this.

Is there a way to add a class to a button on a form in drupal?



3 Answers 3


I don't have experience with the admin overlay, but from what you are writing, I understand that you want to add the class "overlay-close" to an element (admin overlay?) when submit button is pressed. You can adapt the following code for that:

  // Add "overlay-close" class to the proper element
  • Thanks for the suggestion Obidiu I. and in theory it should work, but for some reason I cannot get it to add the class to the element on submit, or on click of the button. I suspect it's because I have enabled ajax processing for the form, but not 100% sure.
    – Metalskin
    Jan 8, 2012 at 0:13
  • I'm going to close this question, as I've decided to go the path of a custom overlay via jquery tools overlay and use custom jquery to process the submit from the overlay. Again, thank you for your suggestion Ovidiu I, I'm sure that it would work if I didn't have jquery enabled.
    – Metalskin
    Jan 8, 2012 at 4:28

Old question but I googled to this question a couple of times before figuring out an answer. Rather than adding a class to the button you could use the hook_form_FORM_ID_alter() to add a callback function when the user clicks the submit button, and then in that callback function tell the overlay to close with the overlay_close_dialog function. This worked for me:

* Implementation of hook_form_FORM_ID_alter()
* *
function mymodule_form_FORM_ID_alter(&$form, &$form_state) {
  $form['#submit'][] = 'mymodule_callback';

//callback after saving form to close overlay
function mymodule_callback(&$form, &$form_state) {
  // Form API will re-render the current page and pass the redirect information to the overlay JavaScript 
  overlay_close_dialog($url, $url_settings);
  // stay on the same page after all submit callbacks have been processed.
  $form_state['redirect'] = FALSE;

See https://api.acquia.com/api/drupal/modules!overlay!overlay.module/function/overlay_form_submit/7 for more on overlay_close_dialog options


The simplest way is to put this code in your submit handler:

if (module_exists('overlay') && overlay_get_mode() == 'child') {
  $form_state['redirect'] = FALSE;

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.