2

I wrote this module that print the node/add form for a content type (article) in a ctools modal window. It works and the new node is saved, but the modal window remains opened after submitting the form.

I would like to automatically close the modal window after saving the node, end and optionally redirect drupal to the new node. Any hint?

      <?php


    function modaltest_menu()
    {
    $items['modaltest']            = array(
        'title' => 'Modaltest Page',
        'page callback' => 'modaltest_page',
        'access arguments' => TRUE
    );
    $items['modaltest/%ctools_js'] = array(
        'title' => 'Modaltest page 2',
        'page callback' => 'modaltest_page_modal',
        'page arguments' => array(
            1
        ),
        'access arguments' => TRUE
    );
    return $items;
}


      function modaltest_page_modal($js = NULL)
    {
      $nojs_message = t('Hello World');
    if (!$js) {
        return $nojs_message;
    }
    module_load_include('inc', 'node', 'node.pages');
    $form = node_add('article');
    ctools_include('modal');
    ctools_include('ajax');
    $output   = array();
    $output[] = ctools_modal_command_display(t('My modal test'), $form);
    print ajax_render($output);
    exit();
}


    function modaltest_page()
    {
    ctools_include('modal');
    ctools_include('ajax');
    ctools_modal_add_js();
    return ctools_modal_text_button(t('Popup link'), 'modaltest/nojs',      t('test popup'), 'ctools-modal-test-style');
    }
  • What's the point of closing the modal if you're redirecting immediately afterwards? – Fabian Iwand Oct 13 '15 at 15:21
  • Indeed you are right, if redirect to a different page, closing the modal window is not needed. So my question comes down to how close the modal window just after submitting the form. – Little Bears Oct 13 '15 at 15:41
0

ctools_modal_command_dismiss() will close the modal.

You can find more information on that command and ctools modals in general by installing the Advanced Help module and visiting /help/ctools/modal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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