title: drupal 7 ctool modal form custom submit handler is not being called
body: <p>I have a requirement where i need to show webform in ctool modal. When user submit the webform it should show the confirmation message in the same ctool modal. This functionality is being used in my project at several places just the webform to show in ctool modal is changing. I googled it and found this <a href="http://drupal.org/node/1196150" rel="nofollow">http://drupal.org/node/1196150</a>. The code i found here helped me now i am able to display the webform in ctool modal and form working very well but the confirmation message is not showing in ctool modal. After submission it show the same form in modal rather then confirmation message. This code attache the custom submit handler with form in hook_form_alter and in this submit handler it set the sessoin variable. On this session variable it make decision whether to show form or confirmation message. </p>
  
  <p>here is code </p>
  
  <pre><code>function webform_modal_menu() { 
    $items['service-page'] = array(
      'title' =&gt; 'Service page',
      'access callback' =&gt; TRUE,
      'page callback' =&gt; 'webform_modal_page',
      );
    $items['modal/%ctools_js/service-webform'] = array(
      'title' =&gt; t("service webform"),
      'page callback' =&gt; 'webform_modal_content',
      'file' =&gt; 'webform_modal.inc',
      'page arguments' =&gt; array(1),
      'access callback' =&gt; TRUE,
      'type' =&gt; MENU_CALLBACK,
    );
  
    return $items;
  }
  
  function webform_modal_page() {
    ctools_include('ajax'); // Module  include the dependence it needs for ajax.
    ctools_include('modal');
    ctools_modal_add_js();
  
    $output = ctools_modal_text_button(t('Click Here'), 'modal/nojs/service-webform', t('Pop me up'));
    $output .= '&lt;div id="modal-message"&gt;&amp;nbsp&lt;/div&gt;';
    ctools_include('plugins');
    return $output;
  }
  
  function webform_modal_content($js = NULL) {
    define('WEBFORM_NID', 14);
    $webform_nid = WEBFORM_NID; // Your webform $nid
    return ctools_ajax_modal_webform($js, $webform_nid);
  }
  
  function webform_modal_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form_id == 'webform_client_form_14') {
      $form['#submit'][2] = '_custom_webform_submit';
    }
  
    function _custom_webform_submit($form, &amp;$form_state) {
      $webform_nid = $form['#node']-&gt;nid;
      lists_session('webform_client_form_'.$webform_nid, $value =  'submitted');
    }
  
    function ctools_ajax_modal_webform($js = NULL, $webform_nid = NULL) {
    $node = node_load($webform_nid); // Load webform node
    $submission =  (object) array(); // empty object required by webform
  
    // React without the modal
    if (!$js) {
      // Webform requires more parameters than standard forms
      return drupal_get_form('webform_client_form_'.$webform_nid, $node, $submission);
    }
  
    // React with the modal
    // Add modal components
    ctools_include('modal');
    ctools_include('ajax');
    $form_state = array(
      'title' =&gt; $node-&gt;title,
      'ajax' =&gt; TRUE,
      );
  
    // Emulate ctools_modal_form_wrapper() form modal.inc because webform can not be triggered trough drupal_build_form
    // If it can, I'd be glad to understand how
    $form_state += array(
      're_render' =&gt; TRUE,
      'no_redirect' =&gt; !empty($form_state['ajax']),
      );
    //drupal_get_form('webform_client_form_'.$webform_nid, $node, $submission);
    $args = array($node, $submission);
    $form_state['build_info']['args'] = $args;
    $output = ctools_modal_form_wrapper('webform_client_form_'.$webform_nid, $form_state);
  
    if ( isset($_SESSION['lists']['webform_client_form_'.$webform_nid]) &amp;&amp; $_SESSION['lists']['webform_client_form_'.$webform_nid] == 'submitted') {
      unset($_SESSION['lists']['webform_client_form_'.$webform_nid]);
      $confirm_message = array("#markup" =&gt; '&lt;div&gt; Your request has been submitted&lt;/div&gt;');
      $confirmation['#markup'] = 
      '&lt;div class="popups-confirmation-wrapper"&gt;'.
      drupal_render($confirm_message).
      '&lt;/div&gt;';    
      $output = array(); // Recreate output
      // Oerwrite the form output if it was successful.
      $output[] = ctools_modal_command_display('Confirmation', $confirmation);
  
    }
  
    // Render output in modal window
    print ajax_render($output);
    exit;
  }
  
  function lists_session($key, $value = NULL) {
    static $storage;
    if ($value) {
      $storage[$key] = $value ;
      $_SESSION['lists'][$key] = $value ;   // I put 'lists' in case some other module uses 'type' in $_SESSION
    }
    else if (empty($storage[$key]) &amp;&amp; isset($_SESSION['lists'][$key])) {
      $storage[$key] = $_SESSION['lists'][$key];
    }
    return $storage[$key];
  }
  </code></pre>
  
  <p>When cache is cleared i directly access modal/nojs/service-webform menu item it show the form and hook_form_alter is called. i confirmed this printing some message in form_alter after directly accessing modal/nojs/service-webform now if i access this url using 'Click here' button which i created on serice-page then it also show that form alter is called and print the message on console(because i am using chromephp for logging.). But if cache is cleared and i click on 'Click here' then form is shown in modal but form_alter is not called because it doesn't print any message in console. After clicking on that button if i access modal/nojs/service-webform directly then also form_alter is not being called. So problem is that custom submit handler is not being called. i confirmed this printing $form variable in form alter. This may make more clear <a href="http://drupal.org/node/1196150#comment-6458176" rel="nofollow">http://drupal.org/node/1196150#comment-6458176</a> Is there any cache issue or i am making some mistake?</p>