1

I would like to automatically create a webform when a new organic group node is created.

The webform should have predefined fields and trigger an email to the group administrator or a user in the group with a predetermined role. Alternatively it could email an address filled out in a cck field on the group content type.

I tried using og_webform but couldn't figure out how to get it to create webforms for each group.

2 Answers 2

1

There is probably multiple was to this. The way I see it is a custom module.

You want to use hook_nodeapi(&$node, $op) in Drupal 6, hook_node_insert($node) in Drupal 7.

You code would look like something like this

CUSTOM_MODULE_NAME_nodeapi(&node, $op) {
  switch ($op) {
    case 'insert':
       if ($node->type == 'group') {
         global $user;

         // Create new object.
         $node = new stdClass();

         // Set desired data and metadata as members in object.
         $node->type = 'predefine_webform_with_predefine_fields';
         $node->uid = $user->uid;
         $node->title = 'node title';
         $node->body = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit...';
         //... prefill other cck fields

         // Save the node
         node_save($node);

       }
       break;
     }
   }
}

(Code should look the same for Drupal 7, minus the switch case)

1
  • This worked, I ended up loading, and saving an existing webform node with a new uid and nid.
    – Arosboro
    Jul 10, 2011 at 11:39
0

To create a node programmatically , on some specific action we have to make some changes in node.module

on line no. 874, find node_save($node) suppose you have a situation where you want to create a node from specific content type i.e. 'page' then. and programmatically node is

story type the code will be

    if($node->type=="page")
         {
    $node_new = new StdClass();
            //creating a bare node

    $node_new->type = 'story ';
    //giving it type

    $node_new->status = 1;
    //give it a published staus

    $node_new->title = "This is story title";
    //gives title

    $node_new->body = "This is story  body";
    //gives body

    node_save($node_new);

    //save it and give it the rest of the attributes    
    //drupal_set_message('Automated '.$node_new->type.'Created');
}

Click Here to view original post

1
  • You meant to hack the file ???
    – AKS
    Nov 3, 2012 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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