Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:55+00:00 2026-06-13T02:07:55+00:00

In my custom module I would like to add the comments functionality. I’ve tried

  • 0

In my custom module I would like to add the comments functionality. I’ve tried a couple of things but didn’t workout so far.

// render comments form
$output .= theme('my_module_front_page'); 
$comment = new stdClass;
$comment->nid = $node_good_practice->nid;
$output .= render(drupal_get_form('comment_form', $comment));
return $output;

The code above puts the comments form to my node page.

But when I fill in the comment form and submit, it redirects me to this page: comment/reply/node id and then i have to fill in my comment all over again and the comment isn’t saved.

I would like to submit and stay on the same page instead of the redirect. And the comment must be saved after submitting.

Right now, the comment form appears on my node page (custom module template). I enter a comment and click on “Save.”
I am sent to /comment/reply/<node_id>, but all the comment fields are empty. The comment isn’t saved either.

What I would like to happen is:

  • Having a comment form on the node page
  • Enter a comment
  • Click on “Save”
  • Drupal saves the comment, and redirect me back to the node/page I was viewing.

Things I’ve tried

  • Adding Redirect

    $form['#redirect'] = "/success-stories/".$node_good_practice->good_practice_name."/".$node_good_practice->nid;
    

    It did not change anything.

  • Changing action

    $form['#action'] = "/success-stories/".$node_good_practice->good_practice_name."/".$node_good_practice->nid;
    

    It redirects me to node/node_id/#comment-17

  • Use drupal_build_form()

    $info->nid = $node_good_practice->nid;
    $comment['build_info']['args'][0] = $info;
    $comment['redirect'] = "http://www.google.nl";
    $output .= render(drupal_build_form('comment_form', $comment));
    

    The form is being displayed, but it does not redirect; it is sent to comment/reply/node_id.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:07:56+00:00Added an answer on June 13, 2026 at 2:07 am

    For some reason the problem was caused by drupal_build_form and drupal_get_form after submitting a comment. If the $_POST was filled the drupal_build_form and the drupal_get_form functions redirects met to /node/node_id/#comment-17 or to /comment/reply/<node_id>
    So i unset the SESSION before loading the form and the problem was fixed.

    So the solution from Mike only works when you unset the SESSION. But he has been verry helpfull.

    So now i have:

    if(isset($_POST['form_id'])) {
      $comment = new stdClass();
      $comment->nid = $good_practice_id; // Node Id the comment will attached to
      $comment->name = $user->name;
      $comment->status = 1;
      $comment->language = "und";
      $comment->subject = $_POST['subject']; 
      $comment->comment_body[$comment->language][0]['value'] = $_POST['comment_body'][$node_good_practice->language][0]['value'];
      $comment->comment_body[$comment->language][0]['format'] = 'filtered_html'; 
      comment_submit($comment);
      comment_save($comment);
      unset($_POST);
    } 
    
    $comment = new stdClass;
    $comment->nid = $node_good_practice->nid;
    $form = drupal_get_form('comment_form', $node_good_practice);
    $form['#action'] = url('success-stories/'.$node_good_practice->good_practice_name.'/'. $comment->nid);
    
    $output .= theme('good_practices_front_detail_page', array('oGoodPractice' => $oGoodPractice, 'aGoodPractices' => $aGoodPractices, 'aComments' => $aComments, 'oSectors' => $oSectors, 'oCountries' => $oCountries, 'links' => $aLinks));
    $output .= render($form);
    $output .= theme('pager', array('tags'=>array()));
    
    return $output;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to register a custom utility / module within YUI3 that is
In Magento I'm creating a custom module and would love to be able to
I'm writing a custom module and I'd like to use $form_state of the current
I've created a custom module citation for academic references. Citations have, among other things,
I would like to override custom user template in my Drupal 7 installation. The
HI, I am trying to create a router for my custom module. I would
Im currently trying to simply add a block to a custom Adminhtml module. i
I have extended the Mage_Adminhtml_Block_Sales_Order_Grid class with a custom module to add several customer
I'm building a custom module and I need to be able to add an
I would like to define my own API to Sugar instances via a Module

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.