I have one cck content type and two fields in this content type
1. is First name
2. is Last name
i am trying TODO when i fill this these fields and click on save button Automatically create Forum topic with the name of first name text box value.
how it is possible ? plz help
i am using Drupal 6


You can do this by little coding. Using hook_form_alter, you have to put your own submit callback and then you can make a custom function that makes another node. Combine some of these snippets and you can achieve what you want.

Form alter should be something like this

Create Nodes programmatically in Drupal 7

  • i am using Drupal 6 :( – Zaid Nov 15 '11 at 13:52
  • it should be the same actually, just some simple functions – ram4nd Nov 15 '11 at 13:53
  • +1, but instead of implementing hook_form_alter and adding your own submit handler, I would simply implement hook_nodeapi and create the forum node from there when $op == 'insert'. – marcvangend Nov 15 '11 at 14:31
  • Is there something like hook_nodeapi in Drupal 7 or in 7 you can do it only with submit callback? – ram4nd Nov 15 '11 at 16:24

You can do it easy with the Rules module.

//Load and init the Drupal System
require_once 'includes/bootstrap.inc';
require_once 'modules/forum/forum.admin.inc';

function fourm_activities_form_alter(&$form, &$form_state, $form_id)

  if($form_id == 'testing_forum_node_form')
    global $base_url;
//      my_debug($form);
    //add function to complete to at the end of array

    if(arg(2) && arg(2)!= 'edit')
    function fourm_activities_form_id_submit_handler($form, &$form_state)

        $name   =   $form['nid']['#post']['field_test'][0]['value'];

        $test_nid = $form_state['nid'];

        global $user;

        $newNode            = (object) NULL;
        $newNode->type      = 'forum';
        $newNode->title     = $name;
        $newNode->uid       = $user->uid;
        $newNode->created   = strtotime("now");
        $newNode->changed   = strtotime("now");
        $newNode->status    = 1;
        $newNode->comment   = 0;
        $newNode->promote   = 0;
        $newNode->moderate  = 0;
        $newNode->sticky    = 0;

        $final_nid =    $newNode->nid;

        $node = node_load($test_nid);
        $node->field_forum_reference[0]['nid'] = $final_nid;

        //$form_state['clicked_button']['#post']['field_forum_reference']['nid']['nid'] = $newNode->nid;

  • I don't understand what I'm seeing here. Why are you bootstrapping Drupal? Is this a stand-alone php script? In that case, it's not a real module and I don't see how your form_alter implementation could work like this. You may want to read some pages from the Module Developers Guide. – marcvangend Nov 20 '11 at 20:06

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.