Hi there,

I've been googling for this for quite a while now but can't seem to find a good solution to my problem. Basically, I'm using the comment module on a website for two purposes, once for the forum (lots of things glued together using advanced_forum) and then for a custom node type & module. However, I want the two comment entry forms to have a different look, in one case the whole thing should be embedded in a collapsed fieldset and only contain a textbox and submit button, whereas in the second case, I don't want the fieldset, but want the whole extra fields (Your name; Preview).

Using hook_form_alter, I managed to get the form to look the way I want it; however, I can't seem to figure out how to differentiate between the two cases, i.e. how to change the form one way if we are currently rendering a node of type X rather than type Y.

Is there any clean way to do that? The only solution I've come up with at this point was to clone the comment module and then enabling "comment" for the forum and "comment-clone" for my nodetype, but thought there should be something more elegant possible than that?

Thanks a lot in advance for your help

kmh

Comments

karlmoritz’s picture

Found a solution as follows:

node.tpl.php:

global $my_nodetype;
$my_nodetype = $node->type;

and then in my.module:

function my_form_alter(...)

global $my_nodetype;
if($my_nodetype == 'mynode') {
...
}

This does the trick for me - if there is a more elegant / more Drupal way without using global variables, I'd be happy to hear about it, though.

glennnz’s picture

@karlmoritz

Karl

I can't get this to work.

I've copied and pasted your changes directly with no luck.

In node.tpl.php:

  <?php
  global $my_nodetype;
  $my_nodetype = $node->type;
  ?>

In my module file:

function course_pre_requirements_form_alter($form_id, &$form) {
  global $my_nodetype;
  if($my_nodetype == 'rbtpa_course') {
  ........

This is making no changes at all to my node type.

Thanks

Glenn

Glenn
THECA Group