1

In my comment-wrapper.tpl.php I was doing

print render($content['comment_form']); 

which worked fine. But to render the comment-form according to given theme, I tried doing this:

<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>>

   print render($content['comment_form']['author']);  
   print render($content['comment_form']['field_email']);
   print render($content['comment_form']['comment_body']);
   print render($content['comment_form']['actions'['submit']);
   print drupal_render_children($form); 


 if ($content['comments'] && $node->type != 'forum'):
     print render($title_prefix);
    <h2 class="title"><?php print t('Comments'); ?></h2>
     print render($title_suffix);
endif;

This code is printing all the components of the form but the submit button is not working as it should. When I click the submit button it is not giving any reaction. Do I need to add any more lines of code to make this comment form work ? Thank you.

| improve this question | | | | |
2

You forgot to render hidden form fields that are required for the correct work.

Just add this line of code after outputting all visible form fields:

<?php 
  print drupal_render_children($form); 
?>

Also if you output form elements outside form template you need manually add {form} tag In your case you will get

<form id="comment-form" class="comment-form" accept-charset="UTF-8" method="post" action="<?php print url('node/' . $node->nid); ?>#comments">
<?php
  print render($content['comment_form']['author']);  
  print render($content['comment_form']['field_email']);
  print render($content['comment_form']['comment_body']);
  print render($content['comment_form']['actions']['submit']);
  print render($content['comment_form']['actions']['preview']);
  print drupal_render_children($content['comment_form']); 
?>
</form> 
| improve this answer | | | | |
  • I tried that, it didnot work. – Sandesh Yadav Aug 23 '12 at 13:35
  • Please provide full code of your comment-wrapper.tpl.php – Eugene Fidelin Aug 24 '12 at 8:11
  • I edited the question. – Sandesh Yadav Aug 24 '12 at 13:40
  • I edited answer. – Eugene Fidelin Aug 29 '12 at 8:54
  • 1
    I tried this code. Still the button is not working as it should. The click on the button is not showing any reaction. – Sandesh Yadav Aug 29 '12 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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