I need to create a post/comment structure almost exactly like what you're looking at right now: original post with comments, subsequent 'answer' posts with their own comments. In response, I'm displaying a views page with a custom path displaying the original post (content type) and the subsequent answers (also content types). The issue lies with printing comment forms for each of the following nodes.

So far, I'm attempting to use the Views PHP field to print the comment form and failing pretty hard. There is D7 comment form doesn't submit relating to this, and Nikit's solution did produce a comment form on demand. However, this form does not submit or preview, submission just redirects the user to the node's comment reply page. Even now I do not understand how this method of calling drupal_get_form() works with two arguments.

So I turned to the trusty Drupal API to reference the drupal_get_form() function and saw that it doesn't take two arguments and returns drupal_build_form() instead. I thought that calling drupal_build_form() straight up might be more appropriate, since from what I could gleam off of the scarce user feedback said I needed to use a form_state['redirect'] of some sort to get users back to the original node page they posted their comments from. As expected however, everything I try returns a pile of errors and gets me nowhere.

The one spot of success was with the Commentsblock module that allowed me to place a real live comment form on a page and actually have the stupid thing submit a comment. While this works for the main content, I'm still at a loss for the subsequent 'answer' comments/forms. In ripping through the source code for the module I discovered comment_node_page_additions($node);, but this does not turn out any valid results either.

There are so many questions here:

  • How does one actually USE the Forms API (and to print comments)?
  • Should I be doing this in a .tpl file instead of Views?
  • Where does the second argument of drupal_get_form() go?
  • What exactly is the difference between drupal_get_form and drupal_build_form and how are they used?
  • Is $form_state['redirect'] called before either of these API calls or after?

This might seem like 'too much' of a question for a single thread, but I'm tired of posting partial questions and getting partial answers. In the interest of education, I would like to build some sort of tutorial either on Drupal.org or elsewhere so that this information can be made available to others in the same situation. Obviously I am not the best person to undertake this due to my massive lack of understanding, but maybe, just maybe with your help this can become a reality.

  1. If you select the 'forms' tag and select its mini menu option 'info', you will see a link to the Drupal pages for the form API and a great basic explanation on how it is used.
  2. You should not use PHP in the view. PHP in content of any sort presents a security risk. The best place to do this is in a custom module.
  3. The form API provides documentation on both.
  4. $form_state is used as central storage for all information about the form. Any part of the $form_state array can be read and written to by any function at any time.

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