diff --git a/ctools_automodal.module b/ctools_automodal.module index e706bc2..e8d6250 100644 --- a/ctools_automodal.module +++ b/ctools_automodal.module @@ -126,10 +126,21 @@ function ctools_automodal_get_form() { ); $commands = ctools_modal_form_wrapper($form_id, $form_state); - if (empty($commands)) { + if (!empty($form_state['executed'])) { + // We'll just overwrite the form output if it was successful. + $commands = array(); + ctools_add_js('ajax-responder'); + if (isset($form_state['destination'])) { + $commands[] = ctools_ajax_command_redirect($form_state['destination']); + } + else { + $commands[] = ctools_ajax_command_reload(); + } + } + elseif (empty($commands)) { $commands[] = ctools_modal_command_loading(); - if (!empty($_GET['destination'])) { - $commands[] = ctools_ajax_command_redirect($_GET['destination']); + if (!empty($form_state['destination'])) { + $commands[] = ctools_ajax_command_redirect($form_state['destination']); } } print ajax_render($commands);