I have created view to display images and when I click on the image it gets displayed in pop-up form. I want to allow user to comment on image in pop-up form only so i have displayed comment form with php code. But its not working properly. It displaying preview button instead of comment. And when I click on preview it redirects to the image node page which should not be happened. I want it to work properly please help me suggesting solution. Hope image below will help you to understand what actually I have done.enter image description here

1 Answer 1


First, in your content type edit page, make the "Preview Before Submit" option disabled or optional. Once you do that you will see the Submit button.

Even you make the Submit button appear, the same will happen and user will be redirected to the actual page with no modal display. From the pattern of your modal window, I guess you are using colorbox plugin. If yes then you need to open this colorbox as an iframe option.

    $(function () {
        $(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});    

So even you submit the page, the page will not be redirected outside of modal.

Then I think you may have to alter the form you are using and check for form elements with a debug() function. Then I guess in your form_alter you can do the following,

  function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if (isset($form['type']) && $form_id == 'mymodule_node_form') {
      // Hide the preview/submit button.
      $form['actions']['preview']['#access'] = FALSE;

Have a check on the variable that sets the preview, by

variable_get('comment_preview_' . $node_type);

If it's set then can be disabled via,

variable_set('comment_preview_' . $node_type, DRUPAL_DISABLED);

I hope this will be helpful to your cause.

  • Yes I am using colorbox plugin. And also disabled preview option on content type edit page but still the preview button is visible. This might be because of the code I have used to print comment form. Hope it will help you. print drupal_render(drupal_get_form("comment_node_node_gallery_item_form", (object) array('nid' =>$row->nid))); print render($content['comments']['comment_form']);
    – D-pak
    Jul 16, 2014 at 5:52
  • Have a look at the EDIT#1. This may help you. Jul 16, 2014 at 6:30
  • Yes its working fine for some extent that is at the place of preview button now its displaying submit button which is working absolutely fine. Thanks Aneek, But after commenting its redirecting user to the node page of the image.
    – D-pak
    Jul 21, 2014 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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