2

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

2 Answers 2

1

You can do it easy with the Rules module.

0
//Load and init the Drupal System
require_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once 'modules/forum/forum.admin.inc';

function fourm_activities_form_alter(&$form, &$form_state, $form_id)
{
my_debug($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')
    {
        $form['buttons']['submit']['#submit'][]='fourm_activities_form_id_submit_handler';
    }
  }
}
    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;

        node_save($newNode);
        $final_nid =    $newNode->nid;

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

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

}
1
  • 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. Commented Nov 20, 2011 at 20:06

Your Answer

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

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