When I add the code (found elsewhere on the site), the Automodal module DOES successfully automatically close the modal window on submit... works great.

Problem is, it also breaks the admin so I can't activate/deactivate modules or change some admin settings. I have tried with/without the code and with/without the module... this is the culprit:



/***
 *  Automatically close on form submit
 */


function automodal_form_alter(&$form, $form_state, $form_id) {
  $form['#action'] = '';  
  $form['buttons']['submit']['#submit'][] = 'automodal_close_form_submit';
  if ($_GET['automodal']=='true') {
    $form['#submit'][] = 'automodal_close_form_submit';    
    modalframe_child_js();
  }
}

function automodal_close_form_submit($form, &$form_state) {
  if ($form_state['values']['op'] == t('Save')) {
      modalframe_close_dialog(array('redirect' => TRUE));
  }
}

I have been adding this to the end of the automodal module to get it to work. This would be a great optional feature to add... if it didn't break the admin!

thoughts?

ron

Comments

mfer’s picture

Status: Active » Closed (duplicate)

This is a dupe of #685364: close modal on form submit.

Something for this will go in soon. :)

rlnorthcutt’s picture

For any who tread here later - the problem was that I was overriding the submit function on every form. I just needed to move the

if ($_GET['automodal']=='true')

Like this:

/***
*  Automatically close on form submit
*/


function automodal_form_alter(&$form, $form_state, $form_id) {
  if ($_GET['automodal']=='true') {
    $form['#action'] = '';  
    $form['buttons']['submit']['#submit'][] = 'automodal_close_form_submit';
    $form['#submit'][] = 'automodal_close_form_submit';    
    modalframe_child_js();
  }
}

function automodal_close_form_submit($form, &$form_state) {
  if ($form_state['values']['op'] == t('Save')) {
      modalframe_close_dialog(array('redirect' => TRUE));
  }
}

It all seems to work fine for now - but hopefully a better solution will be patched in soon.

Berliner-dupe’s picture

This Code dont work!

I copy it to the end from automodal.module and refresh the site

Fatal error: Cannot redeclare automodal_form_alter() (previously declared in E:\xampp\htdocs\projekt\sites\all\modules\automodal\automodal.module:191) in E:\xampp\htdocs\projekt\sites\all\modules\automodal\automodal.module on line 228

line 228 is }

mfer’s picture

@Berliner The closing functionality is already built into the automodal module. Disregard #2.