Comment form is not working with ctools popup I want to display a comment form in popup in drupal 7 website.

I have created a custom module to display comment form in ctools modal and added a link in the views page. Comment form is displaying correctly in ctools modal but comment is not saving when submitting the form.

When we submit the comment form, it does not display any error and redirect to comment form.

I am also using Ajax comments module in the site.

Code snippets for the ctools

/**
 * Implements hook_menu().
 */
function custom_feature_menu() {

  $items = array();

  $items['modal/%ctools_js/comment-popup/%'] = array(
    'title' =&gt; t('Comment Block'),
    'page callback' =&gt; 'custom_feature_comment_callback',
    'page arguments' =&gt; array(1, 3),
    'access callback' =&gt; TRUE,
  );

  return $items;

}


/**
 * Callback for
 */
function custom_feature_comment_callback($js = NULL, $nid = NULL) {

  $node = node_load($nid);
  // setting these defaults is needed, otherwise warnings result in dblog

  if (!$js) {
    return drupal_get_form('comment_node_'.$node-&gt;type.'_form', (object)$edit);
  }

  $form_id = 'comment_node_' . $node-&gt;type . '_form';

  ctools_include('modal');
  ctools_include('ajax');

  $comment = (object) array('nid' =&gt; $node-&gt;nid);

  $form_state = array(
    'title' =&gt; 'Write a Reivew (' . $node-&gt;title . ')',
    'ajax' =&gt; true,
  );

  $form_state['build_info']['args'] = array($comment);

  $commands = ctools_modal_form_wrapper($form_id, $form_state);

  if (!empty($form_state['executed'])) {

    $commands = array();

    $commands[] = ctools_modal_command_dismiss(t('Your comment has been saved.'));
    $commands = ctools_ajax_command_reload();
  }

  //If form is submittedd
  print ajax_render($commands);

}


I have searched in google and follow the below reference but comment form is not saving comment.


http://internetdevels.com/blog/ctools-modal-api   
https://drupal.org/node/1196150
http://deeson-online.co.uk/labs/insert-form-pop-modal-ctools-and-drupal-7


Thanks in advance.
I have found the issue. There is #action property in comment form which was redirecting to same form when we submit comment form. So, it seems that comment form is not working properly. 

I have set up a global variable to remove #action property of the comment form if comment form is displaying in ctools popup.

/**
 * Callback for
 */
function custom_feature_comment_callback($js = NULL, $nid = NULL) {

  $node = node_load($nid);
  // setting these defaults is needed, otherwise warnings result in dblog

  global $comment_popup;
  $comment_popup = 1;

  if (!$js) {
    return drupal_get_form('comment_node_'.$node-&gt;type.'_form', (object)$edit);
  }

  $form_id = 'comment_node_' . $node-&gt;type . '_form';

  ctools_include('modal');
  ctools_include('ajax');

  $comment = (object) array('nid' =&gt; $node-&gt;nid);

  $form_state = array(
    'title' =&gt; 'Write a Reivew (' . $node-&gt;title . ')',
    'ajax' =&gt; true,
    're_render' =&gt; FALSE,
    'no_redirect' =&gt; TRUE,
  );

  $form_state['build_info']['args'] = array($comment);

  $commands = ctools_modal_form_wrapper($form_id, $form_state);

  if (!empty($form_state['executed']) || !empty($form_state['ajax_commands'])) {

    $commands = array();

    $commands[] = ctools_modal_command_dismiss(t('Your comment has been saved.'));
    $commands[] = ctools_ajax_command_reload();
  }

  //If form is submittedd
  return ajax_deliver(array('#type' =&gt; 'ajax', '#commands' =&gt; $commands));

}


function custom_feature_form_alter(&amp;$form, &amp;$form_state, $form_id ) {

  if ($form_id == 'comment_node_article_form') {

    global $comment_popup;

    if ($comment_popup == 1) {

      $comment = $form_state['comment'];

      // If not replying to a comment, use our dedicated page callback for new
      // comments on nodes.
      if (empty($comment-&gt;cid) &amp;&amp; empty($comment-&gt;pid)) {
        // Change the action to call our function.
        $form['#action'] = url('modal/nojs/comment-popup/' . $comment-&gt;nid);
      }

      $comment_popup = 0;
    }
  }

}