Hi friends,

I am trying to apply modal forms to edit the comment. when i clicked on save button it showing ajax http error, but comment message has been saved and displayed whenever refresh the browser.Please provide the solution.

here i am providing my code.

modal forms.module:
==============
$items['modal_forms/%ctools_js/edit/comment/%node'] = array(
'title' => 'Edit Comment',
'page callback' => 'modal_forms_comment_edit',
'page arguments' => array(1, 4, 5),
'access arguments' => array('post comments'),
'file' => 'modal_forms.pages.inc',
'type' => MENU_CALLBACK,
);
-----------------------------------------------------------------------------
modal_forms.pages.inc:
===============

function modal_forms_comment_edit($js = NULL, $node, $cid = NULL) {
$c = comment_load($cid);
$output = array();
$comment = array(
'pid' => $cid,
'nid' => $node->nid,
);

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

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

$form_state = array(
'build_info' => array(
'args' => array(
$comment
),
),
// 'title' => t('Comment'),
'ajax' => TRUE,
're_render' => FALSE,
'no_redirect' => TRUE,
);

// Should we show the reply box?
if ($node->comment != COMMENT_NODE_OPEN) {
drupal_set_message(t('This discussion is closed: you can\'t post new comments.'), 'error');
drupal_goto('node/' . $node->nid);
}
else {
//$output= drupal_get_form("comment_node_{$node->type}_form", $c);
//$form = drupal_render($output);
$output = drupal_get_form('comment_node_' . $node->type . '_form', (object) $c);
// Remove output bellow the comment.
//unset($output['comment_output_below']);
}

if (!$form_state['executed'] || $form_state['rebuild']) {
$output = ctools_modal_form_render($form_state, $output);

}
else {
// We'll just overwrite the form output if it was successful.
$output = array();
ctools_add_js('ajax-responder');
// @todo: Uncomment once http://drupal.org/node/1587916 is fixed.
//if (is_array($form_state['redirect'])) {
// list($path, $options) = $form_state['redirect'];
// $output[] = ctools_ajax_command_redirect($path, 0, $options);
//}
if (isset($_GET['destination'])) {
$output[] = ctools_ajax_command_redirect($_GET['destination']);
}
else {
$output[] = ctools_ajax_command_reload();
}
}

if ($form_state['executed']){
$output[] = ctools_ajax_command_reload();
}

print ajax_render($output);

}

-----------------------------------------------------------------------------

modal_forms_coment.js:
=================
(function ($) {

Drupal.behaviors.initModalFormsComment = {
attach: function (context, settings) {
$("a[href*='/comment/reply'], a[href*='?q=comment/reply']", context).once('init-modal-forms-comment', function () {
this.href = this.href.replace(/comment\/reply/,'modal_forms/nojs/comment/reply');
}).addClass('ctools-use-modal ctools-modal-modal-popup-medium');

$(".comment-edit a", context).once('init-modal-forms-comment', function () {
var curr_url = this.href.split('comment/');
var new_curr = curr_url[1].split('/edit');
var nid = $('.content .node').attr('id').split('-');
this.href = this.href.replace(/comment\/[0-9]*\/edit/,'modal_forms/nojs/edit/comment/'+nid[1]+'/'+new_curr[0]);
}).addClass('ctools-use-modal ctools-modal-modal-popup-medium');

}
};

})(jQuery);

-----------------------------------------------------

Thanks in advance....

Files: 
CommentFileSizeAuthor
#5 modal_forms_edit_comment_1955366_5.patch3.05 KBfrjo

Comments

sasi.dileep’s picture

Title:Edit coment using modal forms» Edit comment using modal forms
sasi.dileep’s picture

Issue summary:View changes

content update

frank.schram’s picture

I am also interested in getting a fix for this.
Did you find a solution in the mean time?

frjo’s picture

Category:Bug report» Feature request
frank.schram’s picture

I tried the above code, but could not get it working.

frjo’s picture

Status:Active» Needs review
StatusFileSize
new3.05 KB

Please try this patch on the latest 7-dev version.