I've created a customized contact form (I looked at webforms but you couldn't add cck fields to them) and I've been able to successfully save nodes generated from this form as nodes. Everything works great but comments aren't enabled even though they are by default in the content-type settings. What $node->'variable' do I need to set to enable comments?

Comments

nuvious’s picture

Anyone?

lukey’s picture

Did you try setting $node->comment ='2' for read/write or $node->comment='1' for read only?

I'm just going off of what I saw in the node object structure.

lobo235’s picture

If you are using the Node Comments module the following should work for you. This is what worked for me.

    case 'presave':
      if($node->uid == 0 && $node->type == 'mytype') {
        $node->comment = 2;
        $node->node_comment = 2;
      }
      break;

This sets the comment settings for nodes of 'mytype' to Read/Write if the author of the node was Anonymous.

eiriksm’s picture

I encountered this problem today. If anyone else googling for this should end up here, this is my solution (it was drupal 7, but the same applies for d6 i guess):

I used the module Views bulk operations. The easiest way was if VBO had an action already created for enabling comments, but as that wasn’t the case, it is really not a long snippet to execute on each row. Here is the steps I used to achieve what I wanted.

1. Downloaded and enabled views bulk operations
2. Created a view displaying all nodes of the content type I wanted to enable comments on
3. Added a VBO field (this part is slightly different on d6)
4. Enabled the Execute PHP action for this field, and also the “select all nodes” checkbox
5. Added a page display
6. Viewed the view page, selected all nodes and executed the PHP action
7. Entered the following snippet as action

$entity->comment = 2; //replace $entity with whatever VBO says the row represents. Might be different in D6
node_save($entity);

Done!

vvs’s picture

node_object_prepare($entity); // set defaults from node type
node_save($entity);