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' => t('Comment Block'),
'page callback' => 'custom_feature_comment_callback',
'page arguments' => array(1, 3),
'access callback' => 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->type.'_form', (object)$edit);
}
$form_id = 'comment_node_' . $node->type . '_form';
ctools_include('modal');
ctools_include('ajax');
$comment = (object) array('nid' => $node->nid);
$form_state = array(
'title' => 'Write a Reivew (' . $node->title . ')',
'ajax' => 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.